Refreshing Feature Tree Organization in Derived Parts Using the Autodesk Inventor API

When working with derived parts in Autodesk Inventor, maintaining a consistent feature tree organization improves model readability and simplifies downstream design activities. In certain workflows, you may observe that the order of the solid bodies in the derived part browser differs from the organization in the source part after the derive operation.

This article demonstrates how the Autodesk Inventor API can be used to refresh the derived component definition using VBA, helping to reorganize the feature tree.


Observed Behavior

Consider the following example.

The source part contains multiple solid bodies arranged in a specific order within the browser.

Before Running the VBA Macro

The image below shows the original part before the derive operation. Notice the order of the solid bodies in the browser.

Figure 1. Original part showing the initial order of the solid bodies.


After creating the derived part, the browser organization may differ from the original ordering.

Derived Part Before Applying the Workaround

The derived part displays the solid bodies in a different order from the source part.

Figure 2. Derived part showing a different organization of the solid bodies in the browser.


VBA-Based Refresh

The following VBA macro refreshes the derived component definition by temporarily excluding all derived solids and then re-including them individually.

Prerequisites

Before running the macro:

  • Open the derived part document.
  • Ensure it is the active document in Autodesk Inventor.
  • Open the VBA Editor (ALT + F11).
  • Insert the code into a standard VBA module.

VBA Code


Sub Test()

    ' Get the active part document
    Dim oDoc As PartDocument
    Set oDoc = ThisApplication.ActiveDocument

    ' Get the first derived part component
    Dim oDC As DerivedPartComponent
    Set oDC = oDoc.ComponentDefinition.ReferenceComponents. _
        DerivedPartComponents(1)

    ' Get the derived part definition
    Dim oDef As DerivedPartUniformScaleDef
    Set oDef = oDC.Definition

    ' Exclude all derived solids
    oDef.IncludeAllSolids = kDerivedExcludeAll

    Dim i As Long

    ' Re-include each derived solid
    For i = 1 To oDef.Solids.Count

        oDef.Solids(i).DeriveStatus = kDerivedIncludeAll

        ' Apply the updated definition
        oDC.Definition = oDef

        ' Refresh the definition before processing the next solid
        Set oDef = oDC.Definition

    Next i

End Sub

Result After Running the VBA Macro

After executing the macro, Inventor refreshes the derived component definition. The browser is rebuilt, and the organization of the solid bodies is updated.

The refresh is performed programmatically without recreating the derived part manually.


How the Code Works

The macro performs the following steps:

  1. Retrieves the active derived part document.
  2. Accesses the first derived part component.
  3. Retrieves its current definition.
  4. Temporarily excludes all derived solids.
  5. Re-enables each solid one at a time.
  6. Updates the derived component definition after each change.

Updating the definition causes Inventor to rebuild the derived component, which refreshes the browser organization.


Benefits

  • Eliminates the need to manually recreate the derived part.
  • Provides a simple API-based workflow for refreshing derived component definitions.
  • Can be integrated into Inventor automation or batch-processing solutions.
  • Uses only standard Autodesk Inventor API functionality.

Conclusion

The Autodesk Inventor API provides powerful capabilities for automating repetitive CAD workflows. Refreshing the derived component definition through the API is a straightforward technique that can be incorporated into automation scripts when working with derived parts.

If you encounter similar browser organization behavior in your own workflows, this VBA approach offers a practical method for refreshing the derived component definition programmatically.

Note: The screenshots shown above are provided solely to illustrate the workflow and the effect of the VBA implementation. They demonstrate the browser organization before and after executing the macro, independent of any specific customer design data.

Discover more from Autodesk Developer Blog

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

Continue reading