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

This might get you closer to your goal.

Dim oADoc As AssemblyDocument = ThisApplication.ActiveDocument
'define the variable "oName"
oName = "ModelState1"
For Each oOcc As ComponentOccurrence  In oADoc.ComponentDefinition.Occurrences
    If TypeOf oOcc.Definition Is PartComponentDefinition Then
		Dim oPDef As PartComponentDefinition = oOcc.Definition
		Dim oFound As Boolean  = False
		For Each oMS As ModelState In oPDef.ModelStates
			If oMS.Name = oName Then
				oFound = True
				Exit For 'found it, so don't create it
			End If
		Next
		If oFound = False Then
			'did not find it, so create it
			oPDef.ModelStates.Add(oName)
		End If
		oOcc.ActiveModelState = oName
	End If
Next

If this solved your problem, or answered your question, please click ACCEPT SOLUTION.
Or, if this helped you, please click (LIKE or KUDOS) :thumbs_up:.

If you want and have time, I would appreciate your Vote(s) for My IDEAS :light_bulb: or you can Explore My CONTRIBUTIONS

Wesley Crihfield

EESignature

(Not an Autodesk Employee)