In an assembly, retrieve an attribute of an iPart, that belongs initially to its factory

By Augusto Goncalves

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


Comments

2 responses to “In an assembly, retrieve an attribute of an iPart, that belongs initially to its factory”

  1. What if I want reference to some sketch at the iPart to use it for projection.

  2. Hi Toni,
    Can you please create a case at Inventor Customization Forum using following link?
    https://forums.autodesk.com/t5/inventor-customization/bd-p/120
    In this case, please explain the requirement in details with example iPart (Make sure that iPart is non-confidential one).
    Thanks and regards,
    Chandra shekar Gopal.

Leave a Reply

Discover more from Autodesk Developer Blog

Subscribe now to keep reading and get access to the full archive.

Continue reading