Ohhh... I forgot that the face it is retrieving from the other document, is in the context of that other document, and the assembly constraint needs a reference to that face in the context of the main assembly...so it needs a FaceProxy, instead of a regular Face. I think I know what it is missing now. My brain is getting tired today.😪
Here try this:
Dim componentA = Components.Add("perete_intermediar", "perete_intermediar.ipt", position := Nothing, grounded := False, visible := True, appearance := Nothing)
Dim oCompADoc As Document = componentA.Occurrence.ReferencedDocumentDescriptor.ReferencedDocument
oNEs = iLogicVb.Automation.GetNamedEntities(oCompADoc)
Dim oEntityName As String = "edge_jos"
Dim oEntity As Face = Nothing
If oNEs.NameExists(oEntityName) = False Then
MsgBox("Could not find any entity in the document named: " & oEntityName, vbCritical, "")
Exit Sub
Else
Try
oEntity = oNEs.FindEntity(oEntityName)
Catch
MsgBox("Error trying to retrieve named entity from document.", vbCritical, "")
Exit Sub
End Try
End If
If IsNothing(oEntity) Then
MsgBox("No entity was retrieved from the document.", vbCritical, "")
Exit Sub
End If
'create the variable to hold the FaceProxy that the method below will get the reference to
Dim oFace1 As FaceProxy = Nothing
'now use this method to set the value to that variable we just created
componentA.Occurrence.CreateGeometryProxy(oEntity, oFace1)
Dim oFace2 As Face = ThisApplication.CommandManager.Pick(SelectionFilterEnum.kPartFacePlanarFilter, "Pick a face. press Esc to cancel")
Dim oAsm As AssemblyDocument = ThisDoc.Document
Try
oAsm.ComponentDefinition.Constraints.AddMateConstraint(oFace1, oFace2, 0)
Catch oEx As Exception
MsgBox("AddMateConstraint method failed" & vbCrLf & _
oEx.Message & vbCrLf & oEx.StackTrace, vbCritical, "")
End Try
Wesley Crihfield

(Not an Autodesk Employee)