Thursday, January 5, 2012

Creating a Basic iLogic Rule with an Event Trigger

You've found some iLogic code online, but you're not sure how to create a simple rule or have it trigger on a save event. You've found the iLogic tutorials on line, but don't have the time to go through them right now. You really just want to know how to create a simple rule and get it working.

Here are some basics to get you going, using some simple example code to update the creation date and author iProperties, as described at this link.

Here is the iLogic Code you'll use:

'set Author iproperty to match the system user name
iProperties.Value("Summary", "Author" ) = ThisApplication.GeneralOptions.UserName
'set the Creattion Date iproperty to the current date
iProperties.Value("Project", "Creation Date" ) = Now
'update the file
iLogicVb.UpdateWhenDone = True

To use this code first create an iLogic Rule:
  1. On the ribbon, click Manage tab > iLogic panel > Add Rule button.
  2. Name the new rule Name-Date.
  3. In the rule text area of the Edit Rule dialog box, simply paste in the code from above.
  4. Click OK to save this new rule.
Next you need to have a couple of text fields that read the iProperties (you'd likely create these text objects in your title block, but for now just create some simple text on your drawing to test this first).
  1. On the ribbon, click Annotate tab > Text panel > Text button.
  2. Click on screen to place the text
  3. In the Format Text dialog box select the Type pull down and choose Properties - Model from the list.
  4. Then select the Property pull down and choose Creation Date from the list.
  5. Then click the Add Text Parameter button (looks like and X with an arrow) to "push" the field to the text box.  
  6. Click OK to create the text.
  7. Repeat these steps for the Author iProperty
Next set the rule to trigger when the file is saved.
  1. On the ribbon, click Manage tab > iLogic panel > Event Triggers button. A dialog box displays the list of available events.
  2. Click the Before Save Document event in the list.
  3. Click Select Rules, or right-click and choose Select Rules from the context menu.
  4. Place a check mark next to the Name-Date rule.
  5. Click OK.
  6. Click OK to close the event list.
Now whenever this file is saved the date and name text fields are updated.
You might also be interested in this post from the guys at the Being Inventive blog:

And this article from Paul Munford: 

And this article from Steve Bedder: