FaceProxy to Name

FaceProxy to Name

RajivAngoelal
Contributor Contributor
1,847 Views
6 Replies
Message 1 of 7

FaceProxy to Name

RajivAngoelal
Contributor
Contributor

Hello Guys,

 

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

am using  parts called RHS_O and RHS_1.

 

The following is a constraint called SC and the "Bottom" and "Left" are iMates between the part:

 

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

 

The code so far:

 

Dim doc As AssemblyDocument = ThisApplication.ActiveDocument

Dim face1 As Face = ThisApplication.CommandManager.Pick(
SelectionFilterEnum.kPartFaceFilter, "Select Face1")
Dim face2 As Face = ThisApplication.CommandManager.Pick(
SelectionFilterEnum.kPartFaceFilter, "Select Face1")

Dim occ1 As ComponentOccurrence = face1.Parent.Parent
Dim occ2 As ComponentOccurrence = face2.Parent.Parent

Dim faceProxie1 As FaceProxy = Nothing
Dim faceProxie2 As FaceProxy = Nothing

occ1.CreateGeometryProxy(face1, faceProxie1)
occ2.CreateGeometryProxy(face2, faceProxie2)

doc.ComponentDefinition.Constraints.AddMateConstraint(faceProxie1, faceProxie2, "FlushParameterDistance = 10mm")

 

Now i would like to get the names of the faceProxies1 and  faceProxies1


MessageBox.Show(faceProxie1.Name???, "Title")

In this case the proxynames should be "Bottom".

 

Help is much appreciated :).

0 Likes
Accepted solutions (1)
1,848 Views
6 Replies
Replies (6)
Message 2 of 7

J-Camper
Advisor
Advisor

Did you assign the Face a name or is that the name of the associated Surfacebody?

 

For the name of the Parent SurfaceBody that the Face belongs to this should work:

Dim doc As AssemblyDocument = ThisApplication.ActiveDocument

Dim face1 As Face = ThisApplication.CommandManager.Pick(
SelectionFilterEnum.kPartFaceFilter, "Select Face1")
Dim face2 As Face = ThisApplication.CommandManager.Pick(
SelectionFilterEnum.kPartFaceFilter, "Select Face2")

Dim occ1 As ComponentOccurrence = face1.Parent.Parent
Dim occ2 As ComponentOccurrence = face2.Parent.Parent

Dim faceProxie1 As FaceProxy = Nothing
Dim faceProxie2 As FaceProxy = Nothing

occ1.CreateGeometryProxy(face1, faceProxie1)
occ2.CreateGeometryProxy(face2, faceProxie2)

doc.ComponentDefinition.Constraints.AddMateConstraint(faceProxie1, faceProxie2, "FlushParameterDistance = 10mm")

'Messagebox to show SurfaceBody Names
MessageBox.Show(faceProxie1.Parent.Name & vbCrLf & _
				faceProxie2.Parent.Name, "Surfacebody Name")

If you actually used the Assign name feature to name the face itself, I would need look into how to access that Feature info, as I have not done so before.

 

0 Likes
Message 3 of 7

RajivAngoelal
Contributor
Contributor

Dear JCamper,

 

Thank you for your reply :).

 

With the faceProxie1.Parent.Name i now get the result Solid1,Solid1.

I gave each face a name or gave every face an iMate. (for now i doesnt matter, which one works is fine with me). 

 

FaceNamesPartLevel.png

 

The constraint:

Constraints.AddMate("Mate:3", "RHS_1:1", "Top","RHS_0:1", "Front")

 

I would like to retrieve the names "Top" and "Front"  of the faces in the messagebox.

Is it possible to do this?

 

Kind regards,

 

0 Likes
Message 4 of 7

J-Camper
Advisor
Advisor
Accepted solution

Okay, I think this is what you are looking for:

Dim doc As AssemblyDocument = ThisApplication.ActiveDocument

Dim face1 As Face = ThisApplication.CommandManager.Pick(
SelectionFilterEnum.kPartFaceFilter, "Select Face1")
Dim face2 As Face = ThisApplication.CommandManager.Pick(
SelectionFilterEnum.kPartFaceFilter, "Select Face2")

Dim occ1 As ComponentOccurrence = face1.Parent.Parent
Dim occ2 As ComponentOccurrence = face2.Parent.Parent

Dim faceProxie1 As FaceProxy = Nothing
Dim faceProxie2 As FaceProxy = Nothing

occ1.CreateGeometryProxy(face1, faceProxie1)
occ2.CreateGeometryProxy(face2, faceProxie2)

doc.ComponentDefinition.Constraints.AddMateConstraint(faceProxie1, faceProxie2, "FlushParameterDistance = 10mm")

'Messagebox to show Assigned Names
Dim AssignedNames As String() = {"Failed1", "Failed2"}
For Each oEntity In iLogicVb.Automation.GetNamedEntities(occ1.Definition.Document).Entities
	If oEntity.Type = kFaceObject
		If oEntity.InternalName = faceProxie1.NativeObject.InternalName
			AssignedNames(0) = (iLogicVb.Automation.GetNamedEntities(occ1.Definition.Document).GetName(oEntity))
		Else If oEntity.InternalName = faceProxie2.NativeObject.InternalName
			AssignedNames(1) = (iLogicVb.Automation.GetNamedEntities(occ2.Definition.Document).GetName(oEntity))
		End If
	End If
Next
MessageBox.Show("Face name from faceProxie1: " & AssignedNames(0) & vbCrLf & vbCrLf & _
				"Face name from faceProxie2: " & AssignedNames(1), "Title")

It shows "Failed" if the face picked was not assigned a name.

0 Likes
Message 5 of 7

RajivAngoelal
Contributor
Contributor

Dear JCamper,

 

Thank you so much for your effort  :D. you really have made my day.

I also learned a lot from your code.

 

I already succed to retrieve names with planes and with your help: the (assigned) names.

 

I don't want to be bold, but is this also possible to retreve an iMate in the same way?

(I want to make a code that completly compatible with every workflow of every inventor user.)

 

Again thank you so much. i'm really grateful 😄

 

 

 

 

0 Likes
Message 6 of 7

J-Camper
Advisor
Advisor

This doesn't seem to pick up the named iMates themselves, but it does pick up work planes, work points, work axes, and assigned name geometry.  This loops through an assembly displaying for all named entities for each document, so you can see what this method brings you:

Sub Main
If ThisApplication.ActiveDocument.DocumentType <> kAssemblyDocumentObject Then Exit Sub
For Each oDoc As Document In ThisApplication.ActiveDocument.AllReferencedDocuments
	For Each oEntity In iLogicVb.Automation.GetNamedEntities(oDoc).Entities
		MessageBox.Show("Name found: " & iLogicVb.Automation.GetNamedEntities(oDoc).GetName(oEntity) & vbCrLf & vbCrLf & _
						"Type of entity: " & oEntity.Type, "Entity Stats: " & oDoc.DisplayName)
		Next
Next
End Sub

 

0 Likes
Message 7 of 7

RajivAngoelal
Contributor
Contributor

Thank you again for your effort 🙂

0 Likes