iLogic: find/modify properties of a given assembly constraint

iLogic: find/modify properties of a given assembly constraint

Anonymous
Not applicable
901 Views
2 Replies
Message 1 of 3

iLogic: find/modify properties of a given assembly constraint

Anonymous
Not applicable

I create several (hundreds)  constraints similar to

Dim ComponentName As String = "MyComponent1"
Dim OtherComponent As String = "MyComponent2"
Dim OtherComponentFace As String = "MyComponent2_TopFace"
Dim offset As Double

Constraints.AddFlush("Constr:" & ComponentName & ":1", ComponentName, "XY Plane", OtherComponent, OtherComponentFace, offset)

 

Assuming I know the name of a constraint, for example "Constr:MyComponent1:1", I want to retrieve:

  • entityName2 (in this case "MyComponent2_TopFace")
  • The parameter name of the offset

I would also like to be able to change the entityName2/OtherComponentFace without deleting the constraint and creating a new one, if that is possible. (to speed it up, since there are many constraints)

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

JhoelForshav
Mentor
Mentor
Accepted solution

Hi @Anonymous 

Try this:

Dim oAsm As AssemblyDocument = ThisDoc.Document
Dim oConstraint As AssemblyConstraint = oAsm.ComponentDefinition.Constraints.Item("Flush:1") 'Name of constraint
Dim oOcc2 As ComponentOccurrence = oConstraint.AffectedOccurrenceTwo
Dim oOccDoc As Document = oOcc2.Definition.Document

iLogicVb.Automation.GetNamedEntities(oOccDoc).GetName(oConstraint.EntityTwo.NativeObject)
Dim Msg As String = "Entity 2 Name: " & iLogicVb.Automation.GetNamedEntities(oOccDoc).GetName(oConstraint.EntityTwo.NativeObject) & vbCrLf _
& "Offset parameter: " & oConstraint.Offset.Name
MsgBox(Msg)


'Change entity two to face named "face0"------------------------------------------------------------
Dim oProx As Object
oOcc2.CreateGeometryProxy(iLogicVb.Automation.GetNamedEntities(oOccDoc).FindEntity("face0"), oProx)
Dim oOffsetVal As Double = oConstraint.Offset.Value 'Due to some bug we have to store the offset value and re-apply it later
Dim oName As String = oConstraint.Name 
oConstraint.ConvertToFlushConstraint(oConstraint.EntityOne, oProx, oConstraint.Offset)
oConstraint.Offset.Value = oOffsetVal
Try
oConstraint.Name = oName
Catch
End Try
'-----------------------------------------------------------------------------------------------------
iLogicVb.UpdateWhenDone = True

The redefining of the constraint isn't very beautiful, but it's the only way I could find...

Message 3 of 3

Anonymous
Not applicable

Thanks a lot, it works just the way I wanted!