Porting guide from Level of Details to Model states.

by Chandra shekar Gopal,

Introduction to Model States

Model States were introduced in Inventor 2022. While product documentation covers the basics well, our ADN team has offered extensive support for developers transitioning to this feature. With Inventor 2023 now released, it’s a good time to review code migration requirements and discuss some known issues.

Official Documentation

These links, provided for Inventor 2023, also apply to Inventor 2022:

Key Observations

“Design Options” and “varying configurations” are important facets of Model States. Compared to the older Level of Detail (LOD) feature, Model States offer improved flexibility—but can also present migration challenges.

Developer Impact

Inventor developers have generally experienced smooth transitions between versions. However, Model States represent the most disruptive change to date. We’d love to hear how we can better support you—please leave your thoughts in the comments below.

Conversion of Level of Detail into Model State

Understanding how LODs convert to Model States is crucial. See the documentation here:

About Level of Detail Migration

API Aspects

Autodesk has updated the API documentation to help developers. Reference:

Working with Model States

Legacy API: Accessing LOD in Inventor 2021

Sub GetLods()
    Dim sFileName As String
    sFileName = "C:TempAssembly1.iam"
    
    Dim oDoc As AssemblyDocument
    Set oDoc = ThisApplication.Documents.Open(sFileName)
    
    Dim oAssemblyCompDef As AssemblyComponentDefinition
    Set oAssemblyCompDef = oDoc.ComponentDefinition
    
    Dim oLODs As LevelOfDetailRepresentations
    Set oLODs = oAssemblyCompDef.RepresentationsManager.LevelOfDetailRepresentations
    
    Dim oLOD As LevelOfDetailRepresentation
    For Each oLOD In oLODs
        Debug.Print oLOD.Name
    Next
    
    oDoc.Close True
End Sub

Different Types of Documents with Respect to Model State

Parts or assemblies fall into one of three categories:

  • Plain Document
  • Model State Document
  • iComponent (iPart/iAssembly) Document

Document Type Boolean Table

TypeIsModelState
Factory
IsModelState
Member
IsiPartFactoryIsiPartMemberIsiAssembly
Factory
IsiAssembly
Member
Plain Document      
Model State FactoryTrue     
Model State Member True    
iPart Factory  True   
iPart Member   True  
iAssembly Factory    True 
iAssembly Member     True

Factory vs Member Documents

Model State Factory Document

  • Fully editable
  • Drives all variations
  • Includes UI frame
  • Not stored on disk

Model State Member Document

  • Represents a variation
  • Non-modifiable (if factory exists)
  • No full UI
  • Multiple members per file

Accessing iProperties via Apprentice Server API

In Inventor 2022, ApprenticeServerDocument.PropertySets returns only active model state properties. Use FilePropertySets (added in Inventor 2022.1) for editable iProperties.

Behavioral Notes

IsModifiable in Inventor 2022

When a Model State is added, IsModifiable = True, blocking property edits via Apprentice. Deleting the model state reverts this.

DocumentDescriptor Behavior

In Inventor 2022, suppressed occurrences were excluded from ReferencedDocumentDescriptors.Count. This is resolved in Inventor 2023.

Checking Dirty States of Model State Members

Dim doc As AssemblyDocument
Set doc = ThisApplication.ActiveDocument

Dim oMs As ModelState
For Each oMs In doc.ComponentDefinition.ModelStates
    If oMs.ModelStateType = kSubstituteModelStateType Then
        Dim oMsDoc As AssemblyDocument
        Set oMsDoc = oMs.Document
        
        If Not oMsDoc Is Nothing Then
            Debug.Print oMs.Document.Dirty
        End If
    End If
Next

Alternative for Substitute Model State

Dim oSub As AssemblyDocument
Set oSub = ThisApplication.Documents.ItemByName("C:\TempAssembly1.iam<substitute1>")
Debug.Print oSub.Dirty
</substitute1>

Substitute LOD iProperties in Pre-2022 Files

In older files, substitute LODs become substitute model states. iProperty access via API was fixed in Inventor 2022.3 and 2023:

Sub GetPartNumber()
    Dim doc As Document
    Set doc = ThisApplication.ActiveDocument
    Debug.Print doc.FullDocumentName

    Dim propSet As PropertySet
    Set propSet = doc.PropertySets.Item("{32853F0F-3444-11D1-9E93-0060B03C1CA6}")

    Dim prop As Property
    Set prop = propSet.Item("Part Number")
    Debug.Print "PartNumber=" & prop.Value
End Sub

Comments

Leave a Reply

Discover more from Autodesk Developer Blog

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

Continue reading