Issue
I have part and derived part based on it. I need to
1. get the base face from derived face
2. get derived face from base face
Solution
1. You can use Face.ReferencedEntity to get the face of base part. Note: Face.ReferencedEntity could be one face or faces.
2. You can
1) use oBaseDoc.ReferencingDocuments to find which file is referenced from the source file.
2) Iterate each derived components in the derived document and find which component is referenced from the source file
3) Iterate each face in the derived component and find which Face.ReferencedEntity is the source face
' get the base face from derived face
Sub getBaseFace()
' assume we have got Inventor application
Dim oDerivedDoc As PartDocument
oDerivedDoc = _InvApplication.ActiveDocument
' assume a face in derived document is selected
Dim oDerivedFace As Face
oDerivedFace = oDerivedDoc.SelectSet(1)
Dim oDerivedDocDef As PartComponentDefinition
oDerivedDocDef = oDerivedDoc.ComponentDefinition
' get the DerivedPartComponent
Dim oDerivedC As DerivedPartComponent
oDerivedC = _
oDerivedDocDef.ReferenceComponents. _
DerivedPartComponents(1)
' get the base document
Dim oBaseDoc As PartDocument
oBaseDoc = _
_InvApplication.Documents.Open( _
oDerivedC.ReferencedDocumentDescriptor.FullDocumentName, _
False)
' get ComponentDefinition of the base part
Dim oBaseDef As PartComponentDefinition
oBaseDef = oBaseDoc.ComponentDefinition
Dim oBaseFace As Face
Dim tempFace As Face
' check which base face is corresponding to the
' derived face
For Each oBaseFace In _
oBaseDef.SurfaceBodies(1).Faces
Try
tempFace = oDerivedFace.ReferencedEntity
'referenced entity is one face
If tempFace Is oBaseFace Then
Debug.Print("found the source face!")
End If
Catch ex As Exception
' referenced entity is faces collection
For Each tempFace In oDerivedFace.ReferencedEntity
If tempFace Is oBaseFace Then
Debug.Print("found the source (base) face!")
End If
Next
End Try
Next
oBaseDoc.Close()
End Sub
' get derived face from base face.
Sub getDerivedFace()
' assume we have got Inventor application
' assume the base document is opened
Dim oBaseDoc As PartDocument
oBaseDoc = _InvApplication.ActiveDocument
' assume a face in the base document is selected
Dim oBaseFace As Face
oBaseFace = oBaseDoc.SelectSet(1)
' iterate each Referencing document(derived document)
Dim oReferencingDoc As PartDocument
For Each oReferencingDoc In _
oBaseDoc.ReferencingDocuments
' get ComponentDefinition of the derived document
Dim oReferencingDocDef As PartComponentDefinition
oReferencingDocDef = oReferencingdDoc.ComponentDefinition
Dim oDerivedC As DerivedPartComponent
For Each oDerivedC In _
oReferencingDocDef.ReferenceComponents. _
DerivedPartComponents
' find what derived component is from the base doc
If oDerivedC.ReferencedDocumentDescriptor. _
FullDocumentName = oBaseDoc.FullDocumentName Then
Dim oDerivedFace As Face
Dim tempFace As Face
For Each oDerivedFace In oDerivedC.PrimaryBody.Faces
Try
tempFace = oDerivedFace.ReferencedEntity
'referenced entity is one face
If tempFace Is oBaseFace Then
Debug.Print( _
"found the derived face!")
End If
Catch ex As Exception
' referenced entity is faces collection
For Each tempFace In _
oDerivedFace.ReferencedEntity
If tempFace Is oBaseFace Then
Debug.Print( _
"found the derived face!")
End If
Next
End Try
Next
End If
Next
Next
End Sub