Watch if the specific parameter(s) changed

By Xiaodong Liang

In default, if the option [Don’t run automatically] is not checked,  the iLogic rule will execute automatically, updating with the newest parameters value when the parameters changed.

image

Or, you could specify which rule needs to execute by iLogic Trigger.

image

But, sometimes, you want only to execute the rule when the specific parameter(s) changed. The two ways above cannot help.

The ModelingEvents.OnParameterChange of Inventor API can know which parameter changed, but it means you would have more effort to work with Inventor events, which may be a challenge to some iLogic users.

Here is one workaround:

You could provide one global file (say "GlobalV.txt")  to store the last values of parameters, e.g. assume we have two parameters: Width and Length. When parameter(s) changed,  the rule runs. It will check the values in "GlobalV.txt" with current values of parameters. If only Width changed, run the corresponding workflow. If Length changed, run the other corresponding workflow. Finally update "GlobalV.txt" with the newest values for next use.  Following is a code snippet:

‘get project path

 </span></i>

Dim oProjPath
oProjPath = ThisApplication.DesignProjectManager.ActiveDesignProject

‘get full path of "GlobalV.txt"

 </span></i>

Dim strGobalVFileName
strGobalVFileName = oProjPath.WorkspacePath & "GlobalV.txt"

If Not System.IO.File.Exists(strGobalVFileName) Then

 ‘ if  "GlobalV.txt" does not exist
  MsgBox ("GlobalV.txt does bnot exist in work path!")

Else

   ‘ read "GlobalV.txt"  

    Dim lines() As String
    lines = System.IO.File.ReadAllLines(strGobalVFileName)

     ‘assume the first line is for Width
    globalV_Width = lines(0)

    ‘assume the second line is for Length
    globalV_Length = lines(1) 

 

    ‘ if global width is different to current width    

 </span></i>

    If Width <> globalV_Width Then

         ‘ do work for Width changing

 </span></i>

    End If   

    ‘ if global length is different to current length    

 </span></i>

    If Length <> globalV_Length Then   

      ‘ do work for Length changing

 </span></i>

    End If

    ‘ now update "GlobalV.txt"  with newest Width and Length for next use.    

 </span></i>

    lines = System.IO.File.ReadAllLines(strGobalVFileName)  

    lines(0) = Width
    lines(1) = Length

    System.IO.File.WriteAllLines
(
strGobalVFileName, lines)

End If

<

p class=”MsoNormal”>

 


Comments

Leave a Reply

Discover more from Autodesk Developer Blog

Subscribe now to keep reading and get access to the full archive.

Continue reading