Issue
If the faces of an iPart have some attributes and the iPart is placed into an assembly, how to iterate the attributes.
Solution
The attributes that are added in the iPart factory document are not preserved in the iPart members. So the attributes cannot be retrieved when the iPart is inserted into the assembly. To get the attribute, iPartMember should be used.
Suppose there is an iPart whose faces have some attributes. Place the iPart into an assembly. The code below demonstrates how to iterate the attributes using the iPartMember.
In VB.Net
Sub RetrieveAttribute()
Dim m_inventorApp As Inventor.Application = Nothing
' Try to get an active instance of Inventor
Try
m_inventorApp = System.Runtime.InteropServices.Marshal.
GetActiveObject("Inventor.Application")
Catch ex As Exception
End Try
' If not active, create a new Inventor session
If m_inventorApp Is Nothing Then
Dim inventorAppType As Type = System.Type.
GetTypeFromProgID("Inventor.Application")
m_inventorApp = System.Activator.CreateInstance(
inventorAppType)
End If
Dim oAsmDoc As AssemblyDocument
oAsmDoc = m_inventorApp.ActiveDocument
Dim oOcc As ComponentOccurrence
oOcc = oAsmDoc.ComponentDefinition.Occurrences.Item(1)
Dim oPartDef As PartComponentDefinition
oPartDef = oOcc.Definition
Dim oDoc As PartDocument
oDoc = oPartDef.iPartMember.ParentFactory.Parent
Dim oSurfaceBody As SurfaceBody
oSurfaceBody = oDoc.ComponentDefinition.SurfaceBodies.Item(1)
Dim oFace As Face
For Each oFace In oSurfaceBody.Faces
Dim oAttribSet As AttributeSet
For Each oAttribSet In oFace.AttributeSets
Dim oAttrib As Inventor.Attribute
For Each oAttrib In oAttribSet
Debug.Print("Name: " + oAttrib.Name +
" Value: " + oAttrib.Value)
Next
Next
Next
End Sub