Model state is introduced to both Part and Assembly documents since Inventor 2022, and the LOD(Level of Detail) in assembly will be removed from UI, the LOD related APIs will be hidden, so all the LOD related funcitons need to be migrated to Model State. In assembly, most of the functions that can work in legacy LOD can also work in model state, only some functions in legacy LOD are changed, and in model state there are some enhancements against legacy LOD(e.g. the file properties can be overriden for each model state). Because of this big change, API developers may need to know how this will impact the API behaviors.
1. The legacy LevelOfDetailRepresentation objects are migrated to ModelState objects. So the FullDocumentName will represent the “FullFileName<ModelState>” instead of legacy “FullFileName<LevelofDetail>”.
1. PartComponentDefinition.ModelStates/AssemblyComponentDefinition.ModelStates: Access Model States.
2. AssemblyComponentDefinition/PartComponentDefinition.IsModelStateFactory/IsModelStateMember : Determine whether the document is model state factory or member document.
If the document is a model state member document, ComponentDefinition/ModelState.FactoryDocument can be used to get the relative model state factory document.
3. ComponentOccurrence.ActiveModelState:Switch ComponentOccurrence model state. It is required that ComponentOccurrence.Definition.Document is up-to-date; otherwise, Save dialog would pop up to ask for document save, a failure will occur if user chooses not to save.
4. ComponentOccurrence.Replace/Replace2 will use the last active model state by default.
5. BOMView.ModelStateMemberName returns the model state member name that current BOMView is based on.
6. PropertySets edit is impacted by ModelStates.MemberEditScope.
If MemberEditScope is set to kEditActiveMember, editting Property’s value for active ModelState just overrides the value for the active ModelState; otherwise the value will be applied to the Property for all ModelState. The Document.FilePropertySets represents the iProperties in Shell Extension for Part/Assembly documents.
7. AddBendTableWithOptions:Support to add bend table with specified model state.
8. AddConfigurationTable:Support to create table with specifying model states.
9. DocumentDescriptor.ReferencedModelState:Tell the model state type of the DocumentDescriptor.
10. ModelingEvents.OnGenerateModelStateMember:To monitor when the model state member is generated.
11. FileOpenOptions.DefaultModelStateInAssembly&DefaultModelStateInPart:Set default model state when opening assembly or part document.
12. In Apprentice:
ApprenticeServerComponent.Open can open part or assembly with specifying model state in FullDocumentName, but it always opens the model state factory document.
ApprenticeServerDocument.ComponentDefinition.ModelStates is not accessible at present. FileManager.GetModelStates/GetModelStateName/GetLastActiveModelState are supported in Apprentice.
13. For custom addin: Environment.PreserveWhenSwitchModelState allows addin to preserve its environment when switch model states. For built-in addin this API will always return True to keep legacy behavior.
Level of Detail APIs | Model State APIs |
---|---|
FullDocumentName (e.g. “C:\Assembly1.iam<Level of Detail1>”) | FullDocumentName (e.g. “C:\Assembly1.iam<Model State1>”) |
ComponentOccurrence. ActiveLevelOfDetailRepresentation | ComponentOccurrence.ActiveModelState |
DerivedAssemblyDefinition. ActiveLevelOfDetailRepresentation | DerivedAssemblyDefinition.ActiveModelState |
DerivedPartDefinition.ActiveModelState | |
ShrinkwrapDefinition.ActiveLevelOfDetailRepresentation | ShrinkwrapDefinition.ActiveModelState |
AssemblyComponentDefinition. RepresentationsManager. LevelOfDetailRepresentations | AssemblyComponentDefinition.ModelStates |
PartComponentDefinition.ModelStates | |
RepresentationsManager.ActiveLevelOfDetailRepresentation | ModelStates.ActiveModelState |
FileOpenOptions.DefaultLevelOfDetail | FileOpenOptions.DefaultModelStateInAssembly |
FileOpenOptions.DefaultModelStateInPart | |
SaveOptions.DefaultToSaveForModelStateUpdates | |
FileManager.GetLastActiveLevelOfDetailRepresentation | FileManager.GetLastActiveModelState |
FileManager.GetLevelOfDetailName | FileManager.GetModelStateName |
FileManager.GetLevelOfDetailRepresentations | FileManager.GetModelStates |
AssemblyComponentDefinition.IsModelStateFactory | |
AssemblyComponentDefinition.IsModelStateMember | |
AssemblyComponentDefinition.FactoryDocument | |
PartComponentDefinition.IsModelStateFactory | |
PartComponentDefinition.IsModelStateMember | |
PartComponentDefinition.FactoryDocument | |
LevelOfDetailEnum | ModelStateTypeEnum |
RepresentationEvents | ModelStateEvents |
RepresentationEvents.OnActivateLevelOfDetailRepresentation | ModelStateEvents.OnActivateModelState |
RepresentationEvents.OnDelete | ModelStateEvents.OnDeleteModelState |
RepresentationEvents.OnNewLevelOfDetailRepresentation | ModelStateEvents.OnNewModelState |
BOMView.ModelStateMemberName | |
AssemblyDocument.LevelOfDetailName | AssemblyDocument.ModelStateName |
PartDocument.ModelStateName | |
ModelingEvents.OnGenerateModelStateMember | |
DocumentDescriptor.ReferencedLevelOfDetail | DocumentDescriptor.ReferencedModelState |
DrawingView.ActiveLevelOfDetailRepresentation | DrawingView.ActiveModelState & SetActiveModelState |
DesignViewRepresentation.CopyToLevelOfDetail | DesignViewRepresentation. CopyComponentVisibilityToSuppression |
ModelState.CopyComponentSuppressionToVisibility | |
BrowserNode(Level of Detail root).NativeObject = LevelOfDetailRepresentation | BrowserNode(ModelStates).NativeObject = ModelState |
Get model state names in a document. Place an Assembly1.iam to C:\Temp folder firstly:
Sub GetModelStateNames() Dim sFileName As String sFileName = "C:\Temp\Assembly1.iam" Dim oDoc As AssemblyDocument Set oDoc = ThisApplication.Documents.Open(sFileName) Dim oAssemblyCompDef As AssemblyComponentDefinition Set oAssemblyCompDef = oDoc.ComponentDefinition ' Get ModelStates collection object. Dim oModelStates As ModelStates Set oModelStates = oAssemblyCompDef.ModelStates ' Get all model state names from ModelStsates object. Dim oModelState As ModelState For Each oModelState In oModelStates Debug.Print oModelState.Name Next oDoc.Close True ' Get all model state name from FileManager Dim oFileManager As FileManager Set oFileManager = ThisApplication.FileManager Dim sModelStateNames() As String sModelStateNames = oFileManager.GetModelStates(sFileName) Dim sName As Variant For Each sName In sModelStateNames Debug.Print sName Next End Sub |
Switch model state for a ComponentOccurrence. Open an assembly with occurrences(not virtual component):
Sub SwitchActiveModelStateOfOccurrence() Dim oDoc As AssemblyDocument Set oDoc = ThisApplication.ActiveDocument Dim oAssemblyCompDef As AssemblyComponentDefinition Set oAssemblyCompDef = oDoc.ComponentDefinition ' Specify an occurrence to change its active model state. Dim oOccu As ComponentOccurrence Set oOccu = oAssemblyCompDef.Occurrences(1) ' Get native document ComponentDefinition of occurrence. Dim oOccuDef As ComponentDefinition Set oOccuDef = oOccu.Definition ' Before switch the active model state of an occurrence you should check if the document is up to date. If oOccuDef.Document.RequiresUpdate Then MsgBox("Can not switch active model state because the native document is not up to date!") Else Dim oModelStates As ModelStates Set oModelStates = oOccuDef.ModelStates Dim oModelState As ModelState For Each oModelState In oModelStates If oModelState.Name <> oOccu.ActiveModelState Then oOccu.ActiveModelState = oModelState.Name Exit Sub End If Next End If End Sub |
As each substitute in an assembly has its own Document pointer, when query each and every occurrences in an .iam file you should query the occurrences from Primary model state and also iterate each and every substitue to get their occurrences. Also when deal with attributes and reference keys each substitute has its own document context, so when use AttributeManager or ReferenceKeyManager you should consider the Document for each substitute but not only the Primary model state.
Model state member document is generated(if not yet) when a ModelState is specified to create a ComponentOccurrence, DrawingView, DerivedPart and DerivedAssembly etc..
Model state member document is not modifiable(Document.IsModifiable returns True) in below situations: