Get Named Face of iPartFactory

One enhancement in Inventor 2019 was the ability to Assign Name to objects – see iLogic Enhancements

I wrote about how you could automate that in Automate creation of Named Geometry

This feature is something that you could also use to mark objects in an iPart factory and use that later on to find them when its member is used in an assembly.

Here is an article on the difficulties of finding derived objects in iPart members: Get edge in derived part that drives work point 

Let’s say we have these files:

NamedFaceAll

The Named Face in the iPart Factory will not show up in the iPart Member, so we’ll have to figure out the connection ourselves using the ReferencedEntity property of the Face in the member document.   

Once we have that we need to also get the Face Proxy representing the specific Face of the iPart Member inside the Assembly, so that we can do things with it, like selecting it in the UI.

We can achieve all that using the following code – this is VBA 

Sub TestSelectNamedFace()
Dim selSet As SelectSet
Set selSet = ThisApplication.ActiveDocument.SelectSet
Dim occ As ComponentOccurrence
Set occ = selSet(1)
Call selSet.Clear
Call selSet.Select(GetNamedFace(occ, "MyFace"))
End Sub
Function GetNamedFace(occ As ComponentOccurrence, name As String) As Face
Dim memberDoc As PartDocument
Set memberDoc = occ.Definition.Document
If Not memberDoc.ComponentDefinition.IsiPartMember Then
Call MsgBox("Not an iPart member based occurrence")
End If
Dim factoryDoc As PartDocument
Set factoryDoc = memberDoc.ComponentDefinition. _
iPartMember.ReferencedDocumentDescriptor.ReferencedDocument
Dim addin As ApplicationAddIn
Set addin = ThisApplication.ApplicationAddIns. _
ItemById("{3BDD8D79-2179-4B11-8A5A-257B1C0263AC}")
Dim iLogicAuto As Object
Set iLogicAuto = addin.Automation
Dim namedEntities As Object
Set namedEntities = iLogicAuto.GetNamedEntities(factoryDoc)
Dim f As Face
Set f = namedEntities.FindEntity(name)
If f Is Nothing Then
Call MsgBox("Did not find named Face")
End If
Dim f2 As Face
For Each f2 In memberDoc.ComponentDefinition.SurfaceBodies(1).Faces
If f2.ReferencedEntity Is f Then
' Get the face into the context of the assembly
Call occ.CreateGeometryProxy(f2, GetNamedFace)
Exit Function
End If
Next
End Function

First select the relevant occurrence in the assembly then run the code:

NamedFace5

You can find info on NamedEntities object and its functions like FindEntity() here 

-Adam


Comments

Leave a Reply

Discover more from Autodesk Developer Blog

Subscribe now to keep reading and get access to the full archive.

Continue reading