Announcements
Attention for Customers without Multi-Factor Authentication or Single Sign-On - OTP Verification rolls out April 2025. Read all about it here.
JhoelForshav
in reply to: Anonymous

Hi @Anonymous 

From what I can tell, you can only name faces in parts, not assemblies. I guess because the faces doesn't really exist in the assembly. Whenever you work with a face on assembly level Inventor actually creates a proxy for that face through the occurrence. So we have to find the named face in the part, then create a proxy for it and then use it in the Mate constraint.

 

See example below. I've placed two occurrences of the same part (Part5). So the occurrences are called Part5:1 and Part5:2. I use the document from one of the occurrences to get the Face in the part named "Mate1". Then I create proxies for that face for each part.

 

I then use these proxies to constrain the faces together :slightly_smiling_face:

 

Sub Main
Dim oAsm As AssemblyDocument = ThisDoc.Document
Dim oAsmDef As AssemblyComponentDefinition = oAsm.ComponentDefinition
'Get the occurrences
Dim oOcc1 As ComponentOccurrence = oAsmDef.Occurrences.ItemByName("Part5:1")
Dim oOcc2 As ComponentOccurrence = oAsmDef.Occurrences.ItemByName("Part5:2")
'Find the named face (object in part document)
Dim oFace As Face = GetNamedEntity(oOcc1.Definition.Document, "Mate1")
'Create Proxies for that face through each of the occurrences.
Dim oFaceProx1 As FaceProxy
Dim oFaceProx2 As FaceProxy
oOcc1.CreateGeometryProxy(oFace, oFaceProx1)
oOcc2.CreateGeometryProxy(oFace, oFaceProx2)
'Create a mate constraint
oAsmDef.Constraints.AddMateConstraint(oFaceProx1, oFaceProx2, 0)
End Sub

Public Function GetNamedEntity(doc As Inventor.Document, name As String) As Object
    Dim attribMgr As AttributeManager = doc.AttributeManager
    Dim objsFound As ObjectCollection
    objsFound = attribMgr.FindObjects("iLogicEntityNameSet", "iLogicEntityName", name)
    
    If objsFound.Count > 0 Then
        Return(objsFound.Item(1))
    Else
        Return(Nothing)
    End If
End Function

 

I'll also attach the assembly with this post (Inv 2020).