By Adam Nagy
Let's say we have a drawing (e.g. MyDrawing.idw) that has the following iLogic Rules Event Triggers setup:
We would like to remove the MyDocumentRule document/internal Rule from the Before Save Document event and add MyExternalRule external Rule instead. For testing purposes the external rule ony does this:
MsgBox("MyExternalRule got executed!")
... and MyDocumentRule does this:
MsgBox("MyDocumentRule got executed!")
There is no API to change the Event Triggers settings, however you can do it by modifying property sets used by iLogic for storing the relevant information. My colleague, Mike Deck, looked into this and came up with the following solution.
You can create a template/seed document by hand that has the Event Triggers setup you need and then copy those settings into other documents programmatically. The attached EventDrivenRulesCopy.iLogicVb external Rule can do the copying for you - Download EventDrivenRulesCopy
It only works on external rules. In fact, if the document has event-driven internal rules, this program will delete the Event Triggers for them. It does this for the sake of simplicity: it is copying the exact set of triggers from the source to the destination, without trying to merge them.
Please make a backup of your destination documents before running this, or run it in a temporary project.
This rule will copy the settings for event driven rules from a seed document to all the documents you select. The seed document must have been saved previously. The rule will copy only from part to part, from assembly to assembly, or from drawing to drawing.
To run it:
- Open the seed document. Ensure that this document has all the event-driven external rule links that you want.
- Run the rule. It brings up a file selection dialog.
- Multi-select the destination documents. Make sure you don’t select the seed document in this group.
Note that if the seed document has any event-driven rules that run internal rules, the rule will show an error message and not continue. This is because it is not set up to copy internal rules. It just copies the links to external rules.
Also note that if the destination documents already have some event-driven rules settings (with or without internal rules), this rule will overwrite them. It will replace them with the rule settings from the seed part. It is not smart enough to merge the two sets of rules. (It doesn’t delete the rules themselves: it only deletes the event trigger information.)
The rule can also be used to delete the event-driven rules in the destination documents. It copies the settings from the seed document. So if the seed document has no event-driven rules, it will make sure that the destination documents also have none.
Based on the above info I created a new drawing document called EventSettingsTemplate.idw, added EventDrivenRulesCopy.iLogicVb, and set up the Event Triggers like so:
Once this document was saved and still active, I ran EventDrivenRulesCopy external Rule and selected the drawing file I wanted to modify in the first place, MyDrawing.idw. After that I checked if the settings were copied OK:
I also modied the document and saved it to see if all is working fine and I got the expected message box: