Constrain work axes C#

Top  Previous  Next

Here is how to constrain two work axes of two parts within an assembly

 

       public static void WorkAxisMateTest()

       {

           if (!CurrentDocIsAssembly())

           {

               MessageBox.Show("Non è un assieme");

               return;

           }

           AssemblyDocument AsmDoc = m_Inventor.ActiveDocument as AssemblyDocument;

           AssemblyComponentDefinition AsmDef = AsmDoc.ComponentDefinition;

 

           ComponentOccurrences OccsList = AsmDef.Occurrences;

           ComponentOccurrence SpallaOcc= null, FinPackOcc=null;

 

           foreach (ComponentOccurrence Occ in OccsList)

           {

               string sComponentName = Occ._DisplayName.Substring(0, 8);

 

               if ("30084897" == sComponentName)

               {

                   SpallaOcc = Occ;

               }

 

               if ("30095817" == sComponentName)

               {

                   FinPackOcc = Occ;

               }

           }

 

           if ((SpallaOcc == null) || (FinPackOcc == null))

           {

               MessageBox.Show("Manca spalla e o finpack");

               return;

           }

 

           try

           {

               PartComponentDefinition SpallaCompDef = (PartComponentDefinition)SpallaOcc.Definition;

               PartComponentDefinition FinPackCompDef = (PartComponentDefinition)FinPackOcc.Definition;

 

               WorkAxis WASpalla = SpallaCompDef.WorkAxes["AsseAltoSinistra"];

               WorkAxis WAFinPack = FinPackCompDef.WorkAxes["AsseAltoSinistra"];

 

               // CreateGeometryProxy needs an Object parameter

               Object SpallaAxisProxyObj = null;

               Object FinPackAxisProxyObj = null;

 

               // Create the proxies ...

               SpallaOcc.CreateGeometryProxy(WASpalla, out SpallaAxisProxyObj);

               FinPackOcc.CreateGeometryProxy(WAFinPack, out FinPackAxisProxyObj);

 

               WorkAxisProxy WASpallaProxy = (WorkAxisProxy)SpallaAxisProxyObj;

               WorkAxisProxy WAFinPackProxy = (WorkAxisProxy)FinPackAxisProxyObj;

 

               AsmDef.Constraints.AddMateConstraint(WASpallaProxy, WAFinPackProxy,0.0);

 

           }

           catch (Exception Ex)

           {

               MessageBox.Show("Non sono risucito a fare il vincolo tra assi " + Ex.Message);

           }

       }

 

text here.

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