When you insert an iPart into an assembly, Inventor creates a child part document and stores it on the disk. This new part does not contain any of the attributes from the parent factory.
To retrieve your custom attributes, you have 3 approaches to proceed: pick up one depending on your workflow:
- Every time the user select a Face in the assembly, you retrieve the corresponding Face in the parent factory and get Attributes from it.
- After you insert the new iPart instance in the assembly, you copy the Faces attributes from the parent to the new occurrence. So you won’t need to refer to the factory.
- After you insert the new iPart instance in the assembly, you copy the Faces attributes from the parent to the newly created part itself, then you need to work with the Occurrence.definition or use the NativeObject property to read attributes from the part.
These following VB.NET code samples demonstrate it.
Public Sub RetrieveFaceFromFactory()
Dim oAsmDoc As AssemblyDocument
oAsmDoc = m_inventorApplication.ActiveDocument
Dim oFacePx As FaceProxy
oFacePx = oAsmDoc.SelectSet.item(1)
Dim oOcc As ComponentOccurrence
oOcc = oAsmDoc.ComponentDefinition.Occurrences.item(1)
Dim oFacePxIterator As FaceProxy
Dim FaceIndex As Long
FaceIndex = 1
For Each oFacePxIterator In oOcc.SurfaceBodies.item(1).Faces
If oFacePxIterator Is oFacePx Then
Exit For
End If
FaceIndex = FaceIndex + 1
Next
Dim oPartDef As PartComponentDefinition
oPartDef = oOcc.Definition
Dim oFactoryDoc As PartDocument
oFactoryDoc = oPartDef.iPartMember.ParentFactory.Parent
Dim oNativeFace As Face
oNativeFace = oFactoryDoc.ComponentDefinition. _
SurfaceBodies.Item(1).Faces(FaceIndex)
Dim oAttributeSet As AttributeSet
For Each oAttributeSet In oNativeFace.AttributeSets
Dim oAttribute As Inventor.Attribute
For Each oAttribute In oAttributeSet
Debug.Print(".Attribute Name: " & oAttribute.Name)
Debug.Print(".Attribute Value: " & oAttribute.Value & vbCrLf)
Next
Next
End Sub
Public Sub CopyFaceAttributes()
Dim oAsmDoc As AssemblyDocument
oAsmDoc = m_inventorApplication.ActiveDocument
Dim oOcc As ComponentOccurrence
oOcc = oAsmDoc.ComponentDefinition.Occurrences.item(1)
Dim oOccFaces As Faces
oOccFaces = oOcc.SurfaceBodies.item(1).Faces
Dim oFactoryDoc As PartDocument
oFactoryDoc = oOcc.Definition.iPartMember.ParentFactory.Parent
Dim oNativeFaces As Faces
oNativeFaces = oFactoryDoc.ComponentDefinition. _
SurfaceBodies.Item(1).Faces
Dim i As Long
For i = 1 To oNativeFaces.count
Dim oFacePx As FaceProxy
oFacePx = oOccFaces.item(i)
Dim oAttributeSet As AttributeSet
For Each oAttributeSet In oNativeFaces(i).AttributeSets
Dim oNewAttSet As AttributeSet
oNewAttSet = oFacePx.AttributeSets.Add(oAttributeSet.name)
Dim oAttribute As Inventor.Attribute
For Each oAttribute In oAttributeSet
oNewAttSet.Add(oAttribute.Name, _
oAttribute.ValueType, _
oAttribute.Value)
Next
Next
Next
End Sub