Community
Inventor Programming - iLogic, Macros, AddIns & Apprentice
Inventor iLogic, Macros, AddIns & Apprentice Forum. Share your knowledge, ask questions, and explore popular Inventor topics related to programming, creating add-ins, macros, working with the API or creating iLogic tools.
cancel
Showing results for 
Show  only  | Search instead for 
Did you mean: 

Individual Model State iProperty Access in iLogic

2 REPLIES 2
SOLVED
Reply
Message 1 of 3
eric.frissell26WKQ
211 Views, 2 Replies

Individual Model State iProperty Access in iLogic

Hi, I'm trying to write an iLogic rule to batch apply the model state name to the iProperties fields because if one of those fields is wrong then an update needs to be made in about 8 places and it's really annoying and tedious.  Pretty much have this so far...not sure where to access a model states iProperties.  If anyone has any idea how to proceed or where to find the documentation that'll give some tips that'd be great

 

' ilogic rule ModelStates - Part Number Assignment
Sub Main()
        
        Dim oDoc As Inventor.Document = ThisDoc.Document
        Dim oStates As Inventor.ModelStates
        Dim oState As Inventor.ModelState
        
        For Each oState In oStates ' this line generates error
			activeState = ThisDoc.ActiveModelState
			curState = oDoc.ModelStateName
               
        Next
End Sub

 

 

2 REPLIES 2
Message 2 of 3

Hi,

Try this Rule !

'This Rule is done By MechDS 19.10.2022 
'For Help Please contact me Email: zezo15330@gmail.com 
'Youtube 
'https://www.youtube.com/MechInventor
'Grab cad
'https://grabcad.com/mech.inventor-1

Dim oDoc As Document = ThisApplication.ActiveDocument

Dim oCompDef As ComponentDefinition = oDoc.ComponentDefinition

'Get the existing property
Dim CustomPropSet As PropertySet = oDoc.PropertySets.Item("Inventor User Defined Properties")

Dim oMState As ModelState
Dim MSCount As Integer

Dim oProp() As [Property]
Dim i As Integer

For Each oMState In oCompDef.ModelStates
   i = i + 1
    On Error Resume Next
    oProp(i - 1) = CustomPropSet.Item("MState" & i)
    If oProp(i - 1) Is Nothing Then
    oProp(i - 1) = CustomPropSet.Add(oMState.Name, "MState" & i)
     Else
       oProp(i - 1).value = oMState.Name
     End If
 Next
 
Msgbox("There are " & i & " Model State(s) in the Document" & vbLf & vbLf & "The name(s) is (are) added to The custom Properites", MsgBoxStyle.Information + Msgboxstyle.OkOnly, "Model State")

 

Hope this can help you !

If this solved your problem, or answered your question, please click ACCEPT SOLUTION.

Blue Mech

Add-ins for Inventor!

Message 3 of 3

Works perfectly, thanks MechDS!

Can't find what you're looking for? Ask the community or share your knowledge.

Post to forums  

Autodesk Design & Make Report