Create Constraints Using iLogic & Set Limits

Create Constraints Using iLogic & Set Limits

richard.joseph.pollak
Advocate Advocate
2,054 Views
2 Replies
Message 1 of 3

Create Constraints Using iLogic & Set Limits

richard.joseph.pollak
Advocate
Advocate

I am trying to automate the placement and constraining of chain links within assemblies. I've gotten to the point where I can create mate and angle constraints, but I am having trouble turning my angle constraints into undirected angle constraints with limits. If anybody knows the next step, I would be very grateful to learn from you.

 

Dim oAsmCompDef As AssemblyComponentDefinition
oAsmCompDef = ThisApplication.ActiveDocument.ComponentDefinition
'Right now I am just using two component occurances to test
'this iRule. Later on I will add user inputs
that loop through
'each link in the chain based on what is required
Dim compOcc1 As ComponentOccurrence = Component.InventorComponent("link:1") Dim compOcc2 As ComponentOccurrence = Component.InventorComponent("link:2") 'This portion creates a mate between two work points.
'It does what I want without any issues
'[
Dim oPoint1 As WorkPoint oPoint1 = compOcc1.Definition.WorkPoints("Work Point1") Dim oPoint2 As WorkPoint oPoint2 = compOcc2.Definition.WorkPoints("Work Point2") Dim oproxyPoint1 As WorkPointProxy compOcc1.CreateGeometryProxy(oPoint1, oproxyPoint1) Dim oproxyPoint2 As WorkPointProxy compOcc2.CreateGeometryProxy(oPoint2, oproxyPoint2) Dim oConstraint As MateConstraint oConstraint = oAsmCompDef.Constraints.AddMateConstraint(oproxyPoint1, oproxyPoint2, 0) oConstraint.Name = compOcc1.Name & ":" & compOcc2.Name & " mate" '] 'This is the part I am having trouble with '[ Dim oAxis1 As WorkAxis oAxis1 = compOcc1.Definition.WorkAxes("Z Axis") Dim oAxis2 As WorkAxis oAxis2 = compOcc2.Definition.WorkAxes("Y Axis") Dim oproxyAxis1 As WorkAxisProxy compOcc1.CreateGeometryProxy(oAxis1, oproxyAxis1) Dim oproxyAxis2 As WorkAxisProxy compOcc2.CreateGeometryProxy(oAxis2, oproxyAxis2) Dim oAConstraint As AngleConstraint oAConstraint = oAsmCompDef.Constraints.AddAngleConstraint(oproxyAxis1, oproxyAxis2, 0,)
'I want to make this constraint undirected with a limit from 0 deg to 30 deg oAConstraint.Name = compOcc1.Name & ":" & compOcc2.Name & " angle 1" ']

 

0 Likes
Accepted solutions (1)
2,055 Views
2 Replies
Replies (2)
Message 2 of 3

AlexFielder
Advisor
Advisor
Accepted solution

Hi @richard.joseph.pollak,

 

Whilst I haven't worked with Constraints in this way myself (and in case you haven't seen it already!) I suggest searching for the AddAngleConstraint method in the Inventor API help documentation.

 

Take a look at my Screencast below for how to access this document:

 

After having reviewed the AddAngleConstraint page myself specifically, it doesn't look as though there is a property for it that will allow you to set limits whilst adding the constraint through the API.

 

 

However a further search reveals the "Add mate constraint with limits API Sample" which ought to be adaptable for your needs:

 

 

Public Sub MateConstraintWithLimits()
    ' Set a reference to the assembly component definintion.
    Dim oAsmCompDef As AssemblyComponentDefinition
    Set oAsmCompDef = ThisApplication.ActiveDocument.ComponentDefinition

    ' Set a reference to the select set.
    Dim oSelectSet As SelectSet
    Set oSelectSet = ThisApplication.ActiveDocument.SelectSet

    ' Validate the correct data is in the select set.
    If oSelectSet.Count <> 2 Then
        MsgBox "You must select the two entities valid for mate."
        Exit Sub
    End If

    ' Get the two entities from the select set.
    Dim oBrepEnt1 As Object
    Dim oBrepEnt2 As Object
    Set oBrepEnt1 = oSelectSet.Item(1)
    Set oBrepEnt2 = oSelectSet.Item(2)

    ' Create the mate constraint between the parts, with an offset value of 0.
    Dim oMate As MateConstraint
    Set oMate = oAsmCompDef.Constraints.AddMateConstraint(oBrepEnt1, oBrepEnt2, 0)

    ' Set a maximum value of 2 inches
    oMate.ConstraintLimits.MaximumEnabled = True
    oMate.ConstraintLimits.Maximum.Expression = "2 in"

    ' Set a minimum value of -2 inches
    oMate.ConstraintLimits.MinimumEnabled = True
    oMate.ConstraintLimits.Minimum.Expression = "-2 in"
End Sub

 

I hope this information helps.

 

Cheers,

 

Alex.

Message 3 of 3

richard.joseph.pollak
Advocate
Advocate

Excellent! Thank you for the information. I was able to dig through the Inventor API help documentation to find the other half of the solution.

 

Dim oAConstraint As AngleConstraint
oAConstraint = oAsmCompDef.Constraints.AddAngleConstraint(oproxyAxis1, oproxyAxis2, 0, 78594)
'78594 refers to the undirected angle constraint solution type. 78593 refers to
'directed (which is default), and 78595 is the referenced vector solution oAConstraint.Name = compOcc1.Name & ":" & compOcc2.Name & " angle 1" oAConstraint.ConstraintLimits.MaximumEnabled = True oAConstraint.ConstraintLimits.Maximum.Expression = "30 deg" oAConstraint.ConstraintLimits.MinimumEnabled = True oAConstraint.ConstraintLimits.Minimum.Expression = "0 deg"