Announcements
Attention for Customers without Multi-Factor Authentication or Single Sign-On - OTP Verification rolls out April 2025. Read all about it here.
JelteDeJong
in reply to: WCrihfield

I see @WCrihfield was just a bit faster than me but here is my approach.

Dim doc As AssemblyDocument = ThisDoc.Document
Dim occ As ComponentOccurrence = doc.ComponentDefinition.Occurrences.Item(1)

Dim facDoc As PartDocument = occ.Definition.Document
If (facDoc.ComponentDefinition.IsModelStateMember) Then
    facDoc = facDoc.ComponentDefinition.FactoryDocument
End If
Dim modelStates As ModelStates = facDoc.ComponentDefinition.ModelStates
Dim newModelStateName = "YourNameHere"
Dim modelState As ModelState = modelStates.Add()
modelState.Name = newModelStateName
modelState.Activate()

occ.ActiveModelState = newModelStateName

if you want to know why I find the factory document first then you can read my blog post on that topic.

Jelte de Jong
Did you find this post helpful? Feel free to Like this post.
Did your question get successfully answered? Then click on the ACCEPT SOLUTION button.

EESignature


Blog: hjalte.nl - github.com