WorkAxis constraints

Top  Previous  Next

To constrain two axes together programatically you can use this function:


bool AddMateConstraintOfTwoWorkAxisProxies (CComPtr<AssemblyComponentDefinition>& pAsmCompDef,

                                           CComPtr<WorkAxisProxy>& pWAProxyA,

                                           CComPtr<WorkAxisProxy>& pWAProxyB,

                                           const double kRadiusMm /*=0.0*/)


   // Get the list of constraints of the assembly so you can add a new one

   CComPtr<AssemblyConstraints> pConstraintList = nullptr ;

   HRESULT hRes = pAsmCompDef->get_Constraints(&pConstraintList) ;

   if (FAILED(hRes) || (pConstraintList == nullptr)) {

       ShowCOMError (hRes,L"AddMateConstraintOfTwoWorkAxisProxies could not get constraints.") ;

       return false ;



   // The offset in a axis constraint is a radius about which the axes

   // can rotate. Having a non zero one means a bit more flexiblity.

   CComVariant varOffset(kRadiusMm/10.0); // in cm


   CComPtr<MateConstraint> pMateConstraint  = nullptr ;  

   hRes = pConstraintList->AddMateConstraint(pWAProxyA, pWAProxyB,




                                             gkvarEmpty, gkvarEmpty,


   if ((FAILED(hRes) || (pMateConstraint == nullptr))) {

       ShowCOMError (hRes,L"AddMateConstraintOfTwoWorkAxisProxies failed") ;

       return false ;



   return true ;



Explanation of kRadiusMm here.


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