Constrain work things of a part to the work things of the containing assembly

Top  Previous  Next

You can do it, but remember that you do not need a proxy at the assembly level. You need a proxy for the part because it can move around inside the assembly, but the assembly is, of course, fixed.

 

 

                    // A constraint between object B and a workplane in an assembly

                    WorkPlaneA = m_AsmDef.WorkPlanes[m_iAsmObj]; // m_iAsmObj will be 1 2 or 3 probably

 

                    ComponentDefinition GenDefB = m_OccB.Definition;

                    if (GenDefB.Type == ObjectTypeEnum.kAssemblyComponentDefinitionObject)

                    {

                        AssemblyComponentDefinition AsmDefB = (AssemblyComponentDefinition)m_OccB.Definition;

                        WorkPlaneB = AsmDefB.WorkPlanes[m_iWorkObjB];

                    }

                    else

                    {    // Assume a Part

                        PartComponentDefinition PartDefB = (PartComponentDefinition)m_OccB.Definition;

                        WorkPlaneB = PartDefB.WorkPlanes[m_iWorkObjB];

                    }

 

                    // CreateGeometryProxy needs an Object parameter

                    object ProxyObjB = null;

                    m_OccB.CreateGeometryProxy(WorkPlaneB, out ProxyObjB);

                    WorkPlaneProxy WorkAxisBProxy = (WorkPlaneProxy)ProxyObjB;

 

                    if (m_eCostraintType == Type_e.eMate)

                    {

                        MateConstraint NewCons = null;

                        // Here I use the workplane directly, in the asm, so no need for a proxy

                        NewCons = m_AsmDef.Constraints.AddMateConstraint(WorkPlaneA, WorkAxisBProxy, 0.0);

                        if (m_mmMaxOffset > 0.0)

                        {

                            NewCons.ConstraintLimits.MaximumEnabled = true;

                            NewCons.ConstraintLimits.Maximum.Value = m_mmMaxOffset / 10.0; // Set as cm not mm

                        }

                        NewCons.Name = sName;

                    }

                    else

                    {

                        FlushConstraint NewCons;

                        // Here I use the workplane directly, in the asm, so no need for a proxy

                        NewCons = m_AsmDef.Constraints.AddFlushConstraint(WorkPlaneA, WorkAxisBProxy, 0.0);

                        if (m_mmMaxOffset > 0.0)

                        {

                            NewCons.ConstraintLimits.MaximumEnabled = true;

                            NewCons.ConstraintLimits.Maximum.Value = m_mmMaxOffset / 10.0; // Set as cm not mm

                        }

                        NewCons.Name = sName;

                    }

 

If you see what I mean.

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