Add Insert Constraint to Reference Assembly with Parts
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report
I was trying to use the follow line of code, but the script I wrote opens up an Assembly and then tries to add an insert constraint to that Assembly file. This code only works if I'm adding a constraint to the current Assembly (the Assembly that is active). This is a method from the IManagedConstraints Interface. This method does not accept an oAsmDoc reference.
Constraints.AddInsert(constraintName, partOne, geometryOne, partTwo, geometryTwo, axesOpposed := axesOpposedBool, distance := CDbl(distanceOffset), lockRotation := lockRotationBool)
I then tried to figure out how to use either the AddInsertConstraint or AddInsertConstraint2, but I'm having trouble going from named geometry to an EdgeProxy or whatever object the function will accept. In the following code, the commented out AddInsertConstraint works given a selected edge, but I can't seem to figure out how to go from a named edge to making the constraint. I hope to insert this code into a larger script that works off of an excel sheet. The Select Edge would be deleted and I'd start from a string that matches existing Named Geometry in the parts.
Dim oPartDoc As AssemblyDocument
oPartDoc = ThisApplication.ActiveDocument ' Assuming this is a part document
Dim oDefPart As AssemblyComponentDefinition
oDefPart = oPartDoc.ComponentDefinition
Dim oPartEdge1 As EdgeProxy
oPartEdge1 = ThisApplication.CommandManager.Pick(SelectionFilterEnum.kPartEdgeCircularFilter, "Select Edge")
If oPartEdge1 Is Nothing Then Exit Sub
Dim occ1 As ComponentOccurrence = oPartEdge1.Parent.Parent
Dim oPartEdgeName1 As String
Try
oPartEdgeName1 = iLogicVb.Automation.GetNamedEntities(occ1.Definition.Document).GetName(oPartEdge1)
'oPartEdgeName1 = "Edge1"
test1 = iLogicVb.Automation.GetNamedEntities(occ1.Definition.Document).FindEntity(oPartEdgeName1)
Catch
MsgBox("Failed to get name of selected edge.", , "")
Exit Sub
End Try
MessageBox.Show(oPartEdgeName1, "Title")
Dim oPartEdge2 As EdgeProxy
oPartEdge2 = ThisApplication.CommandManager.Pick(SelectionFilterEnum.kPartEdgeCircularFilter, "Select Edge")
If oPartEdge2 Is Nothing Then Exit Sub
Dim occ2 As ComponentOccurrence = oPartEdge2.Parent.Parent
Dim oPartEdgeName2 As String
Try
oPartEdgeName2 = iLogicVb.Automation.GetNamedEntities(occ2.Definition.Document).GetName(oPartEdge2)
'oPartEdgeName2 = "Edge2"
test2 = iLogicVb.Automation.GetNamedEntities(occ2.Definition.Document).FindEntity(oPartEdgeName2)
Catch
MsgBox("Failed to get name of selected edge.", , "")
Exit Sub
End Try
MessageBox.Show(oPartEdgeName2, "Title")
Try
' The following line works, but I will not have this info in production / the main script
'oDefPart.Constraints.AddInsertConstraint(oPartEdge1, oPartEdge2, True, "0.0")
' The following line does NOT work. Here test1 and test2 are starting from named geometry
oDefPart.Constraints.AddInsertConstraint(test1, test2, True, "0.0")
MessageBox.Show("Insert Constraint added successfully.", "Title")
Catch ex As Exception
MessageBox.Show("Error adding insert constraint: " & ex.Message, "Title")
End Try
What am I doing wrong here? I'd like to be able to replace oPartEdgeName1 with a string, such as "Edge1".
test1.ToString returns "System.__ComObject", which doesn't seem right.