How to read a modelstate property ?

How to read a modelstate property ?

TONELLAL
Collaborator Collaborator
858 Views
2 Replies
Message 1 of 3

How to read a modelstate property ?

TONELLAL
Collaborator
Collaborator

Hello,

On user-side, when you activate a model state, corresponding properties are automatically updated.

I'm trying to do the same thing in VB. I can activate a modelstate, but properties are not updated. What is missing in the code ?

 

Sub test()

 

Dim odoc As PartDocument
Dim oPropSets As PropertySets
Dim oPropSet As PropertySet
Dim oProp As Property
Dim oModelStates As ModelStates
Dim oModelState As ModelState
Dim sPartNumber As String
Dim oActiveModelState As ModelState

 

Set odoc = ThisApplication.ActiveDocument
Set oPropSets = odoc.PropertySets
Set oModelStates = odoc.ComponentDefinition.ModelStates

 

Set oActiveModelState = oModelStates("Principal(e)")
sPartNumber = oPropSets("Design Tracking Properties").Item("Part Number").Value
Debug.Print ("Model state : " & oActiveModelState.Name & vbCrLf & "Part Number : " & sPartNumber)

 

Set oActiveModelState = oModelStates("Etat 1")
sPartNumber = oPropSets("Design Tracking Properties").Item("Part Number").Value
Debug.Print ("Model state : " & oActiveModelState.Name & vbCrLf & "Part Number : " & sPartNumber)

 

'Problem : Part Number is not modified"

 

End Sub

 

Thanks for your help !

 

Alain

0 Likes
Accepted solutions (1)
859 Views
2 Replies
Replies (2)
Message 2 of 3

CattabianiI
Collaborator
Collaborator
Accepted solution

You did not activate the model state.
Assuming the Principal(e) model state is the active one when you execute the code, try this:
Set oActiveModelState = oModelStates("Etat 1")
oActiveModelState.Activate()


Message 3 of 3

TONELLAL
Collaborator
Collaborator

Oops...

0 Likes