How do you identify assembly constraints between two entities if one of the entities is the top level assembly file?

How do you identify assembly constraints between two entities if one of the entities is the top level assembly file?

wfajber
Contributor Contributor
1,296 Views
2 Replies
Message 1 of 3

How do you identify assembly constraints between two entities if one of the entities is the top level assembly file?

wfajber
Contributor
Contributor

I wrote some iLogic to list the assembly constraints. This will eventually go in a tool to check constraints when replacing a large subassembly with another large subassembly to know what constraints are going to be restored.

 

This is a short routine but looks longer because I added a function to convert the constraint type into readable text.

 

The code goes through each constraint and lists each one, as a constraint between Occurrence Entity One and Occurrence Entity Two.  I get the name from the  Occurrence. It works fine between when the Occurrences are parts or sub assemblies. Where it breaks is when the constraint is made from a component occurrence to the assembly origin planes.  When I try to retrieve the Occurrence Entity, it throws an error as top assembly is not a component occurrence in its own file.

 

I am including some little files for demonstration. There is an abundance of Msgbox statements for the purposes of stepping through it.  In the assembly file attached, there are four constraints. The first three are between parts. The last one is a constraint to the assembly file base plane.

 

I do not see how the API provides a way of doing this and looking for help.  The API gets the constraint between two entities but how to tell if one of the entities is the main assembly file?

 

Sub Main
	
Dim acd As Inventor.AssemblyDocument = ThisApplication.ActiveDocument

Dim s As String
Dim con, name1, name2 As String
Dim occ1, occ2 As Inventor.ComponentOccurrence

Dim anyconstraint As Inventor.AssemblyConstraint
For Each anyconstraint In acd.ComponentDefinition.Constraints
	con = ConstraintType(anyconstraint.Type) + anyconstraint.Name 
	MsgBox(con,,"Type of constraint")
	occ1 = anyconstraint.OccurrenceOne
	MsgBox( occ1.Name, , "Name of 1st constraint")
	name1 = occ1.Name
	occ2 = anyconstraint.OccurrenceTwo
	'name1 = anyconstraint.AffectedOccurrenceOne.Name 
	MsgBox( occ2.Name, , "Name of 2nd constraint")
	name2 = anyconstraint.OccurrenceTwo.Name
	s = con+" from " + name1 + " to "+ name2
	MsgBox(s, , "Constraint List")
	Next
	
End Sub

Private Function ConstraintType(ByVal constraintenum As ObjectTypeEnum) As String

        Dim s As String

        If constraintenum = ObjectTypeEnum.kAngleConstraintObject Then
            s = " Angle Assembly Constraint"
        ElseIf constraintenum =ObjectTypeEnum.kAngleConstraintProxyObject Then
            s = " Angle Assembly Constraint Proxy"
        ElseIf constraintenum =ObjectTypeEnum.kAssemblyConstraintsEnumeratorObject Then
            s = " Assembly Constraint Enumerator"
        ElseIf constraintenum =ObjectTypeEnum.kAssemblyConstraintsObject Then
            s = " Assembly Constraints collection"
        ElseIf constraintenum =ObjectTypeEnum.kAssemblySymmetryConstraintObject Then
            s = " Symmetry Assembly Constraint"
        ElseIf constraintenum =ObjectTypeEnum.kAssemblySymmetryConstraintProxyObject Then
            s = " Symmetry Assembly Constraint Proxy"
        ElseIf constraintenum =ObjectTypeEnum.kCompositeConstraintObject Then
            s = " Composite Assembly Constraint"
        ElseIf constraintenum =ObjectTypeEnum.kCustomConstraintObject Then
            s = " Custom Assembly Constraint"
        ElseIf constraintenum =ObjectTypeEnum.kCustomConstraintProxyObject Then
            s = " Custom Assembly Constraint Proxy"
        ElseIf constraintenum =ObjectTypeEnum.kFlushConstraintObject Then
            s = " Flush Assembly Constraint"
        ElseIf constraintenum =ObjectTypeEnum.kFlushConstraintProxyObject Then
            s = " Flush Assembly Constraint Proxy"
        ElseIf constraintenum =ObjectTypeEnum.kInsertConstraintObject Then
            s = " Insert Assembly Constraint"
        ElseIf constraintenum =ObjectTypeEnum.kInsertConstraintProxyObject Then
            s = " Flush Assembly Constraint Proxy"
        ElseIf constraintenum =ObjectTypeEnum.kMateConstraintObject Then
            s = " Mate Assembly Constraint"
        ElseIf constraintenum =ObjectTypeEnum.kMateConstraintProxyObject Then
            s = " Mate Assembly Constraint Proxy"
        ElseIf ObjectTypeEnum.kRotateRotateConstraintObject Then
            s = " Rotate-Rotate Assembly motion Constraint"
        ElseIf constraintenum =ObjectTypeEnum.kRotateRotateConstraintProxyObject Then
            s = " Rotate-Rotate Assembly motion Constraint Proxy"
        ElseIf constraintenum =ObjectTypeEnum.kRotateTranslateConstraintObject Then
            s = " Rotate-Translate Assembly motion Constraint"
        ElseIf ObjectTypeEnum.kRotateTranslateConstraintProxyObject Then
            s = " Rotate-Translate Assembly motion Constraint Proxy"
        ElseIf constraintenum =ObjectTypeEnum.kTangentConstraintObject Then
            s = " Tangent Assembly Constraint"
        ElseIf constraintenum =ObjectTypeEnum.kTangentConstraintProxyObject Then
            s = " Tangent Assembly Constraint Proxy"
        ElseIf ObjectTypeEnum.kTransitionalConstraintObject Then
            s = " Transitional Assembly Constraint"
        ElseIf constraintenum =ObjectTypeEnum.kTransitionalConstraintProxyObject Then
            s = " Transitional Assembly Constraint Proxy"
        ElseIf constraintenum =ObjectTypeEnum.kTranslateTranslateConstraintObject Then
            s = " Translate-Translate Assembly motion Constraint"
        ElseIf constraintenum =ObjectTypeEnum.kTranslateTranslateConstraintProxyObject Then
            s = " Translate-Translate Assembly motion Constraint Proxy"

        Else
            s = " "
        End If

        Return s

    End Function
	

 

 

 

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

Michael.Navara
Advisor
Advisor
Accepted solution

You can check the occurrence is Nothing

See this modified code

Sub Main

	Dim acd As Inventor.AssemblyDocument = ThisApplication.ActiveDocument

	Dim s As String
	Dim con, name1, name2 As String
	Dim occ1, occ2 As Inventor.ComponentOccurrence

	Dim anyconstraint As Inventor.AssemblyConstraint
	For Each anyconstraint In acd.ComponentDefinition.Constraints
		con = ConstraintType(anyconstraint.Type) + anyconstraint.Name
		MsgBox(con, , "Type of constraint")
		occ1 = anyconstraint.OccurrenceOne
		name1 = GetOccurrenceName(occ1)
		MsgBox(name1, , "Name of 1st constraint")
		occ2 = anyconstraint.OccurrenceTwo
		name2 = GetOccurrenceName(occ2)
		MsgBox(name2, , "Name of 2nd constraint")
		s = con + " from " + name1 + " to " + name2
		MsgBox(s, , "Constraint List")
	Next

End Sub

Function GetOccurrenceName(occ As ComponentOccurrence)
	If occ Is Nothing Then
		Return "MainAssembly"
	Else
		Return occ.name
	End If
End Function

 

 

0 Likes
Message 3 of 3

wfajber
Contributor
Contributor
Accepted solution

Very good.

 

If this was in the documentation I could not find it. But there is a logic to it.

 

Restated:

If the assembly constraint is tied to a Component Occurrance of Nothing, then the constraint must to be to work geometry of the assembly file itself.

 

Thanks so much.

0 Likes