Delete Model State via iLogic

Delete Model State via iLogic

zoe.baker-bushby
Enthusiast Enthusiast
645 Views
1 Reply
Message 1 of 2

Delete Model State via iLogic

zoe.baker-bushby
Enthusiast
Enthusiast

Wanting iLogic rule that will clear off all model states except the current active one aka the Master.

 

Understand there is this syntax:

ModelState.Delete()

 

But can not seem to get this to work...

Heres what I have:

Dim doc As AssemblyDocument = ThisDoc.Document
oName = "COURSE 1 STEEL TANK SHEET:8"
occ = doc.ComponentDefinition.Occurrences.ItemByName(oName)
Dim facDoc As PartDocument = occ.Definition.Document

oPCD = facDoc.ComponentDefinition
oMStates = oPCD.ModelStates

Component.ActiveModelState("COURSE 1 STEEL TANK SHEET:8") = "Master"

For Each STATE In oMStates
	MessageBox.Show(STATE.Name)
	If STATE.Name = "Model State1"
'		Delete Model State
	End If
	
Next


iLogicVb.UpdateWhenDone() = True

 

 

Any help would be great, thanks.

 

 

0 Likes
Accepted solutions (1)
646 Views
1 Reply
Reply (1)
Message 2 of 2

CattabianiI
Collaborator
Collaborator
Accepted solution

You've done the most common mistake when working with model states: forgetting about the factory document, which I know it's a very tricky concept.

Here's the solution:

Dim doc As AssemblyDocument = ThisDoc.Document
oName = "COURSE 1 STEEL TANK SHEET:8"
occ = doc.ComponentDefinition.Occurrences.ItemByName(oName)
' Get the factory document, it's from the factory where you
' can delete and do some other impacting operations Dim facDoc As PartDocument = occ.Definition.FactoryDocument
' Sometimes you could have to open explicitly the factory, but ignore this step at the moment oPCD = facDoc.ComponentDefinition oMStates = oPCD.ModelStates
' Activate the master model state in the factory, to be sure you can delete the custom ones
Dim masterMs As ModelState = oMStates.Item("Master")
masterMs.Activate()

' Activate the master model state in the occurrence Component.ActiveModelState("COURSE 1 STEEL TANK SHEET:8") = "Master"
' Loop through factory model states For Each STATE In oMStates MessageBox.Show(STATE.Name) If STATE.Name = "Model State1" ' Delete Model State
STATE.Delete() End If Next iLogicVb.UpdateWhenDone() = True