Working with PropertySets and Model States

By Sajith Subramanian

If you wish to change a Property’s value on a document having Model States, the workflow via API is the similar to the Inventor UI:

  • Activate the required Model State using ModelState.Activate.
  • Set the MemberEditScope to either kEditActiveMember or kEditAllMembers based on whether the updated value would be applied only to the active model state or all members.
  • Get the property from Factory document (and not the Model State document), and change its value.
  • To confirm whether the required Property has been correctly updated, activate the respective Model State and query the property from the Factory Document.

Here is a sample VBA code that exhibits a similar workflow:

Sub ModelStateProps()


Dim oPartDoc  As PartDocument
Set oPartDoc = ThisDocument


Dim oCompDef As PartComponentDefinition
Set oCompDef = oPartDoc.ComponentDefinition


Dim oModelStates As ModelStates
Set oModelStates = oCompDef.ModelStates

‘Fetch the required Model State from the collection

Dim oModelState As ModelState
Set oModelState = oCompDef.ModelStates(“Model State 1”)


‘Activate the model state
oModelState.Activate



‘ Get the design tracking property set for our model state.
Dim oSummaryInfo As Inventor.PropertySet
Set oSummaryInfo = oPartDoc.PropertySets.Item(“Inventor Summary Information”)



‘ Get the Comments property.
Dim oCommentsProperty As Property
Set oCommentsProperty = oSummaryInfo.Item(“Comments”)



‘ Set the Member Edit Scope
oModelStates.MemberEditScope = kEditActiveMember  ‘kEditAllMembers for all members



‘Set the value
oCommentsProperty.Value = “Updating comments via API!”

End Sub

A couple of things to remember:

  • It is recommended to edit in the Factory Document context and activate the Model State you wish to edit.
  • It is not recommended to change the Model State Member Document directly. Also, the Member Document may not exist, if not already generated. Hence, your code would return a ‘Null’ in such cases, as shown below.

modelstates


Comments

One response to “Working with PropertySets and Model States”

  1. Awesom

Leave a Reply

Discover more from Autodesk Developer Blog

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

Continue reading