Constraint an Assembly Workplane with a ComponentOccurence Workplane?

By Augusto Goncalves

The AddFixed method creates a work plane at the specified position in space, but it is not grounded.  Placing a constraint on the work plane could cause it to move depending on what it is being constrained to and the behavior of the solver.  The fact that it is not grounded and still have six degrees of freedom available allows the solver to reposition it as needed.

As a workaround, please set oAssyPlane.Grounded = True before AddMateConstraint and set Grounded back to its original value.

The code below assumes two occurrences in one assembly. The coordinate system of the second occurrence is not aligned with the assembly’s.

Public Sub MateConstraintOfWorkPlanes()

 

  ‘ get the active component definition

  Dim oAsmCompDef As AssemblyComponentDefinition

  oAsmCompDef = m_inventorApplication. _

    ActiveDocument.ComponentDefinition

 

  ‘ get the workplane

  Dim oAssyPlane As WorkPlane

  Dim OPt As Point = Nothing

  Dim XV As UnitVector = Nothing

  Dim YV As UnitVector = Nothing

  oAsmCompDef.WorkPlanes(2). _

    GetPosition(OPt, XV, YV)

  ‘ and add fixed

  oAssyPlane = oAsmCompDef. _

    WorkPlanes.AddFixed(OPt, XV, YV)

 

  ‘ create geometry proxy

  Dim oOcc1 As ComponentOccurrence

  oOcc1 = oAsmCompDef.Occurrences(2)

  Dim oPartPlaneXZ As WorkPlane

  oPartPlaneXZ = oOcc1.Definition.WorkPlanes(2)

  Dim oPartPlane1 As WorkPlaneProxy = Nothing

  oOcc1.CreateGeometryProxy( _

    oPartPlaneXZ, oPartPlane1)

 

  ‘ and finally add the constraint

  Dim oldV As Boolean

  oldV = oAssyPlane.Grounded

  oAssyPlane.Grounded = True

  oAsmCompDef.Constraints.AddMateConstraint( _

    oPartPlane1, oAssyPlane, 0)

  oAssyPlane.Grounded = oldV

End Sub


Comments

Leave a Reply

Discover more from Autodesk Developer Blog

Subscribe now to keep reading and get access to the full archive.

Continue reading