Cheers @bradeneuropeArthur.
I modified your code to work with both Part & Assembly files & also configured it to create an enabling parameter for another parameter (via a form).
Here's the code, in case it helps anyone else:
Sub Main()
'-------------------------------------------------------------------------
' Notes:
'
'-------------------------------------------------------------------------
' Vars:
'-------------------------------------------------------------------------
'
'-------------------------------------------------------------------------
' Get the active document:
'-------------------------------------------------------------------------
'
Dim oDocType = ThisDoc.Document.DocumentType
'
'=========================================================================
' Code for PART:
'=========================================================================
'
If oDocType = DocumentTypeEnum.kPartDocumentObject Then
Dim oPartDoc As PartDocument = ThisDoc.Document
Dim oPartDef As PartComponentDefinition = oPartDoc.ComponentDefinition
'
Try
Parameter("MSQ") = Parameter("MSQ")
Catch
oPartDoc.ComponentDefinition.Parameters.UserParameters.AddByValue("MSQ", False, "BOOLEAN")
End Try
'
If oPartDef.ModelStates.Count>1 Then
Parameter("MSQ") = True
'
End If
'
'=========================================================================
' Code for ASSEMBLY:
'=========================================================================
'
ElseIf oDocType = DocumentTypeEnum.kAssemblyDocumentObject Then
Dim oAssemblyDoc As AssemblyDocument = ThisDoc.Document
Dim oAssemblyDef As AssemblyComponentDefinition = oAssemblyDoc.ComponentDefinition
'
Try
Parameter("MSQ") = Parameter("MSQ")
Catch
oAssemblyDoc.ComponentDefinition.Parameters.UserParameters.AddByValue("MSQ", False, "BOOLEAN")
End Try
'
If oAssemblyDef.ModelStates.Count>1 Then
Parameter("MSQ") = True
'
End If
'
End If
'
End Sub
'
'========================================================================