Add Insert Constraint to Reference Assembly with Parts

Add Insert Constraint to Reference Assembly with Parts

commonmandan
Contributor Contributor
275 Views
1 Reply
Message 1 of 2

Add Insert Constraint to Reference Assembly with Parts

commonmandan
Contributor
Contributor

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. 

0 Likes
276 Views
1 Reply
Reply (1)
Message 2 of 2

A.Acheson
Mentor
Mentor

Hi @commonmandan 

You might have allready  completed this but if your looking to work with the named edge it will need to be made a proxy edge from within the assembly it resides. The pick command tool automatically converts an edge to a proxy which is why you would get that method to work over the named entity. You can check the edge type is either edge or edgeproxy. 

 

Once you have received a entity from a named face/edge you can check the object type to see it is what you expect it to be. 

If this solved a problem, please click (accept) as solution.‌‌‌‌
Or if this helped you, please, click (like)‌‌
Regards
Alan
0 Likes