Activating the most recent model state

How to activate the most recently used model state

In order to activate the most recently used model state it is necessary to know its name prior to opening the document. Inventor provides the GetLastActiveModelState() function to achieve this.

 

To do this in a powerJobs Processor job the document needs to be opened one time to actually get access to the Inventor API. Then the document has to be closed again before calling GetLastActiveModelState(). It has to be close again because the most recently used state will be the master state after opening it.

$openResult = Open-Document -LocalFile $File.LocalPath
$null = Close-Document
$lastActiveModelStateName = $openResult.Application.Instance.FileManager.GetLastActiveModelState($File.LocalPath)

After saving the most recent model state the document can be opened again. A list of all model states can be found on ComponentDefinition.ModelStates and the desired model state can be activated with the Activate() function.

$openResult = Open-Document -LocalFile $File.LocalPath


$lastActiveModelState = $openResult.Document.Instance.ComponentDefinition.ModelStates | Where-Object { $_.Name -eq $lastActiveModelStateName }
$lastActiveModelState.Activate()

Usually it should be possible to use the ModelState opening option, but that doesn't work currently