Showing results for 
Search instead for 
Do you mean 
Reply

Constraining components

Is there a simple method that someone has created to make constraints at a distance between components?

Or any tips. When recording it just come back with a jumbled mess.

 

1 REPLY

Re: Constraining components

Hi,

below some code to constrain a component.

Should be a good start to create a distance constrain. Just record a distance constrain and edit the constrainType and Alignment accordingly. offcourse don't forget the distance value.

 

 

br

Fred

 

componentConstraint1.ConstraintAlignment = Positioning.Constraint.Alignment.CoAlign
componentConstraint1.ConstraintType = Positioning.Constraint.Type.Distance

 

 

 

 

 

   Sub AddConstrainToComponent(cmp1 As Component, dp1 As DatumPlane, dp2 As DatumPlane)

        Dim componentPositioner1 As Positioning.ComponentPositioner
        componentPositioner1 = s.Parts.Work.ComponentAssembly.Positioner

        componentPositioner1.ClearNetwork()
        componentPositioner1.BeginAssemblyConstraints()

        Dim allowInterpartPositioning1 As Boolean
        allowInterpartPositioning1 = s.Preferences.Assemblies.InterpartPositioning

        Dim network1 As Positioning.Network
        network1 = componentPositioner1.EstablishNetwork()

        Dim componentNetwork1 As Positioning.ComponentNetwork = CType(network1, Positioning.ComponentNetwork)

        componentNetwork1.MoveObjectsState = True

        Dim nullAssemblies_Component As Assemblies.Component = Nothing
        componentNetwork1.DisplayComponent = nullAssemblies_Component
        componentNetwork1.NetworkArrangementsMode = Positioning.ComponentNetwork.ArrangementsMode.Existing
        componentNetwork1.MoveObjectsState = True

        Dim markId2 As Session.UndoMarkId
        markId2 = s.SetUndoMark(Session.MarkVisibility.Invisible, "Assembly Constraints Update")

        Dim constraint1 As Positioning.Constraint
        constraint1 = componentPositioner1.CreateConstraint(True)
        Dim componentConstraint1 As Positioning.ComponentConstraint = CType(constraint1, Positioning.ComponentConstraint)
        componentConstraint1.ConstraintAlignment = Positioning.Constraint.Alignment.CoAlign
        componentConstraint1.ConstraintType = Positioning.Constraint.Type.Touch
        componentConstraint1.SetName("ALIGN_XY")

        Dim constraintReference1 As Positioning.ConstraintReference
        constraintReference1 = componentConstraint1.CreateConstraintReference(cmp1, dp1, False, False, False)

        Dim constraintReference2 As Positioning.ConstraintReference
        constraintReference2 = componentConstraint1.CreateConstraintReference(s.Parts.Work.ComponentAssembly, dp2, False, False, False)

        constraintReference2.SetFixHint(True)
        componentNetwork1.Solve()
        componentPositioner1.ClearNetwork()

        Dim nErrs1 As Integer
        nErrs1 = s.UpdateManager.AddToDeleteList(componentNetwork1)

        componentPositioner1.DeleteNonPersistentConstraints()

        Dim nErrs3 As Integer
        nErrs3 = s.UpdateManager.DoUpdate(markId2)

        Dim nullAssemblies_Arrangement As Assemblies.Arrangement = Nothing
        componentPositioner1.PrimaryArrangement = nullAssemblies_Arrangement
        componentPositioner1.EndAssemblyConstraints()



    End Sub