Retrieve iMate Name

Retrieve iMate Name

RajivAngoelal
Contributor Contributor
646 Views
4 Replies
Message 1 of 5

Retrieve iMate Name

RajivAngoelal
Contributor
Contributor

Hello Guys,

 

I want to write a code that retrieves the names of the iMates that has been set in a constraint.

am using j2 parts called RHS_O and RHS_1.

 

The following is a constraint called SC and the "Bottom" and "Left" are iMates between the parts.

Constraints.AddByiMates("SC", "RHS_0:1", "Bottom", "RHS_1:1", "Left")

Now i would like to retrieve the iMates names in a string. 

 

Help is much appreciated :).

0 Likes
Accepted solutions (1)
647 Views
4 Replies
Replies (4)
Message 2 of 5

WCrihfield
Mentor
Mentor

Would this do what you are wanting done?

Dim oADoc As AssemblyDocument = ThisApplication.ActiveDocument
Dim oADef As AssemblyComponentDefinition = oADoc.ComponentDefinition
Dim oConstraints As AssemblyConstraints = oADef.Constraints
Dim oIMName As String = oConstraints.Item("SC").iMateResult.Name

Wesley Crihfield

EESignature

(Not an Autodesk Employee)

0 Likes
Message 3 of 5

RajivAngoelal
Contributor
Contributor

Dear WCrihfield,

 

I will test it and get back to you.

Thank you for your effort 🙂

0 Likes
Message 4 of 5

WCrihfield
Mentor
Mentor
Accepted solution

I think I may have a better solution for you.  I have not tried it out yet, so let me know if this does what you need.

Dim oADoc As AssemblyDocument = ThisApplication.ActiveDocument
Dim oADef As AssemblyComponentDefinition = oADoc.ComponentDefinition
Dim oConstraints As AssemblyConstraints = oADef.Constraints
Dim oConst As AssemblyConstraint

For Each oConst In oConstraints
	If oConst.Name = "SC" Then
		If oConst.ResultOfiMate = True Then
			Dim oiMateDef1 As iMateDefinition
			Dim oEntity1 As iMateDefinition
			oConst.iMateResult.GetInputs(oiMateDef1, oEntity1)
			MessageBox.Show("Constraint Name: " & oConst.Name & vbNewLine &
			"First iMate Name = " & oiMateDef1.Name & vbNewLine &
			"Second Entity Name = " & oEntity1.Name)
		End If
	End If
Next

Wesley Crihfield

EESignature

(Not an Autodesk Employee)

0 Likes
Message 5 of 5

RajivAngoelal
Contributor
Contributor

Sorry for my late reaction, i have a fever.

It works like a charm.

Thank you 😄

0 Likes