Add grounded WorkAxis in an assembly

Top  Previous  Next

There are limits to how you can add work axes in assemblies (and presumably also work points and work planes).  In general they have to be done using AddFixed.


Here's an example:


   CComQIPtr<AssemblyDocument> pAssemblyDoc;

   CComPtr<AssemblyComponentDefinition> pAssemblyCompDef;


   CComPtr<TransientGeometry> pTransGeom = GetTransGeomPtr();


   CComPtr<Application>pApp = theApp.GetInvAppPtr();


   CreateNewAssembly(pAssemblyDoc, pAssemblyCompDef, strTemplateFile);


   CComPtr<WorkAxes> pAsmWorkAxes;



   for (int ix = 0; ix < 3; ix++) {

       double x = ix * 3;

       for (int iy = 0; iy < 3; iy++) {

           double y = iy * 3;

           CComPtr<UnitVector> pUnitVec;

           pTransGeom->CreateUnitVector(0, 0, 1.0, &pUnitVec);


           CComPtr<Point> pPoint;

           pTransGeom->CreatePoint(x, y, 0.0, &pPoint);


           CComPtr<WorkAxis> pNewAxis;

           pAsmWorkAxes->AddFixed(pPoint, pUnitVec, VARIANT_FALSE,&pNewAxis);





Here is an example which starts off with a WorkAxisProxy and adds a WorkAxis in that position.


   CComPtr<TransientGeometry> pTransGeom = GetTransGeomPtr () ;   


   LinePtr pLine = pNodeWAZProxy->GetLine();

   PointPtr pLineRoot = pLine->GetRootPoint();

   UnitVectorPtr pLineDir = pLine->GetDirection();

   CComPtr <Vector> pvecDir  ;

   HRESULT hRes = pLineDir->AsVector(&pvecDir);

   if (FAILED(hRes)) {

       gLogger.Printf(ekErrMsg, "AWAART: Could not get AsVector");

       return false ;



   CComPtr<WorkAxes> pWorkAxes;

   hRes =pCctsAsmCompDef->get_WorkAxes(&pWorkAxes);

   if (FAILED(hRes)) {

       gLogger.Printf(ekErrMsg, "AWAATR: Could not get work axes");

       return false ;



   CComPtr<WorkAxis> pNewWorkAxis;

   pWorkAxes->AddFixed (pLineRoot,pLineDir,VARIANT_FALSE,&pNewWorkAxis) ;

   if (FAILED(hRes)) {

       ShowCOMError (hRes,L"AWAATR: AddFixed (%s) failed",kcsAxisName.GetString ());

       return false ;



   CComBSTR bstrAxisName(kcsAxisName);

   hRes = pNewWorkAxis->put_Name(bstrAxisName);

   if (FAILED(hRes)) {

       gLogger.Printf(ekErrMsg,L"AWAATR: put_Name (%s) failed",LPWSTR(bstrAxisName));

       return false ;



Here is an example in VB:


Public Sub AssemblyWorkAxis()

   Dim asmDoc As AssemblyDocument

   Set asmDoc = ThisApplication.ActiveDocument


   Dim asmDef As AssemblyComponentDefinition

   Set asmDef = asmDoc.ComponentDefinition


   Dim tg As TransientGeometry

   Set tg = ThisApplication.TransientGeometry


   Dim wa As WorkAxis

   Set wa = asmDef.WorkAxes.AddFixed(tg.CreatePoint(0, 0, 0), _

                                     tg.CreateUnitVector(1, 1, 1))

   wa.Grounded = True

End Sub





Text, images and diagrams © 2021 Owen F. Ransen. All rights reserved. (But copy the source code as much as you want!)