iLogic to determine if Files have more than One Model State

iLogic to determine if Files have more than One Model State

arkelec
Collaborator Collaborator
301 Views
2 Replies
Message 1 of 3

iLogic to determine if Files have more than One Model State

arkelec
Collaborator
Collaborator

Is this possible?

 

I've had a look at a few articles, but can't see anything that suits.

 

What I ultimately want to do, is to establish whether a file has more than one Model State & if it does, return a boolean value of 1 to a custom parameter.

 

Thanks in advance.

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

bradeneuropeArthur
Mentor
Mentor
Accepted solution

This will do:

It will create a PMst parameter with a value of 1 if there are more than one Modelstate in the Assembly.

 

Dim a As AssemblyDocument = ThisAssembly.Document
Dim c As AssemblyComponentDefinition = a.ComponentDefinition
Dim UPs As UserParameters = c.Parameters.UserParameters
Dim Up As UserParameter
If c.ModelStates.Count>1 Then
Try
	Up = UPs.Item("PMst")
	Catch
	UPs.AddByValue("PMst",1,"ul")	
	End Try

End If

bradeneuropeArthur_0-1702848772108.png

 

 

Regards,

Arthur Knoors

Autodesk Affiliations & Links:
blue LinkedIn LogoSquare Youtube Logo Isolated on White Background


Autodesk Software:Inventor Professional 2025 | Vault Professional 2024 | Autocad Mechanical 2024
Programming Skills:Vba | Vb.net (Add ins Vault / Inventor, Applications) | I-logic
Programming Examples:
Drawing List!|
Toggle Drawing Sheet!|
Workplane Resize!|
Drawing View Locker!|
Multi Sheet to Mono Sheet!|
Drawing Weld Symbols!|
Drawing View Label Align!|
Open From Balloon!|
Model State Lock!
Posts and Ideas:
My Ideas|
Dimension Component!|
Partlist Export!|
Derive I-properties!|
Vault Prompts Via API!|
Vault Handbook/Manual!|
Drawing Toggle Sheets!|
Vault Defer Update!

! For administrative reasons, please mark a "Solution as solved" when the issue is solved !


 


EESignature

Message 3 of 3

arkelec
Collaborator
Collaborator

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
'
'========================================================================

 

0 Likes