It is not exactly what do you ask, but you can switch ModelState during open process. You need to use the opening sequence to determine which ModelState is requested by user.
Side effect is you are not able to directly open [Primary] model state
It is little bit more code, but I hope you will understand it
Sub Main()
Dim applicationEventsWrapperSharedVariable = "ApplicationEventsWrapper"
If SharedVariable.Exists(applicationEventsWrapperSharedVariable) Then
Dim existingApplicationEventsWrapper = SharedVariable(applicationEventsWrapperSharedVariable)
existingApplicationEventsWrapper.Dispose()
End If
Dim applicationEventsWrapper = New ApplicationEventsWrapper(ThisApplication)
SharedVariable.Value(applicationEventsWrapperSharedVariable) = applicationEventsWrapper
End Sub
Class ApplicationEventsWrapper
Implements IDisposable
Private ReadOnly requestedModelState As String = "My Standard Model State"
Private ReadOnly inventor As Inventor.Application
Private ReadOnly applicationEvents As ApplicationEvents
Private openedDocuments As New List(Of String)
Public Sub New(inventor As Inventor.Application)
Me.inventor = inventor
applicationEvents = Me.inventor.ApplicationEvents
AddHandler applicationEvents.OnOpenDocument, AddressOf ApplicationEvents_OnOpenDocument
End Sub
Public Sub Dispose() Implements IDisposable.Dispose
RemoveHandler applicationEvents.OnOpenDocument, AddressOf ApplicationEvents_OnOpenDocument
openedDocuments.Clear()
End Sub
Private Sub ApplicationEvents_OnOpenDocument(documentObject As _Document,
fullDocumentName As String,
beforeOrAfter As EventTimingEnum,
context As NameValueMap,
ByRef handlingCode As HandlingCodeEnum)
handlingCode = HandlingCodeEnum.kEventNotHandled
Select Case beforeOrAfter
Case EventTimingEnum.kBefore
If NotSpecifiedModelState(fullDocumentName) Then
openedDocuments.Add(fullDocumentName)
End If
Case EventTimingEnum.kAfter
If openedDocuments.Contains(fullDocumentName) Then
TrySwitchModelState(documentObject)
openedDocuments.Remove(fullDocumentName)
End If
Case EventTimingEnum.kAbort
If openedDocuments.Contains(fullDocumentName) Then
openedDocuments.Remove(fullDocumentName)
End If
End Select
End Sub
Private Function NotSpecifiedModelState(fullDocumentName As String) As Boolean
Dim fullFileName As String = inventor.FileManager.GetFullFileName(fullDocumentName)
Return fullFileName = fullDocumentName
End Function
Private Sub TrySwitchModelState(documentObject As _Document)
Dim modelState As ModelState = GetRequestedModelState(documentObject)
If modelState Is Nothing Then Return
modelState.Activate()
End Sub
Private Function GetRequestedModelState(documentObject As _Document) As ModelState
Dim modelStates As ModelStates
Select Case documentObject.DocumentType
Case DocumentTypeEnum.kAssemblyDocumentObject
Dim asm As AssemblyDocument = documentObject
modelStates = asm.ComponentDefinition.ModelStates
Case DocumentTypeEnum.kPartDocumentObject
Dim prt As PartDocument = documentObject
modelStates = prt.ComponentDefinition.ModelStates
Case Else
Return Nothing
End Select
Try
Dim modelState As ModelState = modelStates(requestedModelState)
Return modelState
Catch ex As Exception
Return Nothing
End Try
End Function
End Class