Is there a way to set the event trigger of an ilogic file that's already inside of a document? I have code that can automatically create and populate new rules across my assembly parts, but it would be nice to set certain rules to fire every time that part gets saved.
If it can't be accomplished outright from the API, would it be possible to throw an OnEvent (save event in this case) inside of the iLogic code, to get the same results?
(I've not messed around with events much which is why I'm asking ๐ )
Solved! Go to Solution.
Solved by MegaJerk. Go to Solution.
I have done a lot of digging since I last asked this question, and feel that I have finally found an answer.
Because I see that it is a question that has been asked a few times, and has gotten little in the way of a response, I wanted to revive this thread with my findings so that maybe others won't find themselves as lost as I was.
A copy / paste from my comment over on the Being Inventive Blog : http://beinginventive.typepad.com/being-inventive/2011/10/creating-ilogic-rules-automatically.html
(For some reason, it seems that my comment has disappeared, or is being validated by an admin, so if you don't see it, I apologize)
------------------------------------------------------------------------------
Basically, the Event Triggers that can be found in the Inventor UI, can be set using a document's PropertySet "iLogicEventsRules". Each different Event Trigger has a corresponding Property Name, as well as a Property ID that (seems as if it) has to fall within a number range stemming from a set base value. In addition, each base Property Name ends with a numerical value that indicates the place in line that whatever Property Value (in this case, an iLogic Rule) assigned to it, will fire off.
So as an example, you would end up with a Property that looks something like this :
("Rule1", "AfterDocOpen0", 400)
So we want an iLogic Rule named Rule1 to go off after the document has been opened. Because it's the first rule that has had that Event Trigger applied to it, the "AfterDocOpen" has the lowest numerical value applied to it; 0.
If I wanted to add a different rule to the same Event Trigger, it might look something like this :
("Rule2", "AfterDocOpen1", 401)
Notice how the value after the "AfterDocOpen" has changed? That shows that it will fall into line right after the AfterDocOpen0.
------------------------------------------------------------------------------
I have made a VB.Net Project / source, that I have sent to my Box.com profile for anyone to download : http://www.box.com/s/pzoz3vq88qesz6mcpm1p
Inside of the .zip, you will find all of the source code that I used in making an iLogic rule injector, that also sets up any Event Triggers that the user selects. Essentially it will iterate through a number of user selected files, open them one by one, create the rule that they have made inside of the editor, apply any triggers, save the part and then close it. It was a project that I started in order to make my job a bit easier, but feel that it may make the lives of others, a little easier as well.
NOTE: This is the FIRST proper programming that I've done, so if you find something that breaks it, feel free to send me a PM detailing what went wrong. I tried to do as much testing as I could, but there's always something that a person can miss.
------------------------------------------------------------------------------
Just in case that my comment doesn't end up returning back, over on the Being Inventive blog, I will post the table of the Event Triggers / Names / IDs that I have found so far :
------------------------------------------------------------------------------
CheckList Box Name: : Property Name : : Property ID ---------------------------------------------------------------------------------------- After Open Document : AfterDocOpen : 400 Close(Document) : DocClose : 500 Before Save Document : BeforeDocSave : 700 After Save Document : AfterDocSave : 800 Any Model Parameter Change : AfterAnyParamChange : 1000 Part Geometry Change** : PartBodyChanged : 1200 Material Change** : AfterMaterialChange : 1400 Drawing View Change*** : AfterDrawingViewsUpdate : 1500 iProperty(Change) : AfterAnyiPropertyChange : 1600 Feature Suppression Change** : AfterFeatureSuppressionChange : 2000 Component Suppression Change* : AfterComponentSuppressionChange : 2200 iPart / iAssembly Change Component* : AfterComponentReplace : 2400 New Document : AfterDocNew : 2600
----------------------------------------------------------------------------------------
* Indicates that it's for an Assembly file only
** Indicates that it's for a Part file only
*** Indicates that it's for a Drawing file only.
Hope this can be of use to someone.
I also forgot to mention that if you do not have Visual Studios installed, and simply want to use the application, you should still download the file from my Box.com link (posted in the comment above). Once that file has been unzipped, you can find the most recent build in the : \obj\x86\Release folder, named : Code Injector.exe
Another notice : I've only used this on machines running Inventor 2011! I can not guarantee that this even works with 2012 as we have yet to upgrade. If it turns out that it doesn't work well with 2012, and that no one here can fix it, my workplace will be upgrading to that version of Inventor in about 2 weeks, so I will have a chance to explore fixing it after that time (if it's broken for that version).
Alright. Last post. I found out today that a bit of bad math had snuck into my brain, and subsequently made it into the code that would check against the Property ID of the Event Trigger. Needless to say... it caused problems (IE: Things not working as they should), so I've fixed it with the latest build / source which can be found here : http://www.box.com/s/dvoe410ct7g8kjoqo0tk
Sorry for the re-bump, but there is no way to edit my previous posts it would seem...
Thanks for looking into this. I have been searching for a solution to this for awhile.
http://forums.autodesk.com/t5/Autodesk-Inventor/Apply-iLogic-rule-to-several-files/td-p/2688688
As it stands now, the exe that is included in the latest build should (with luck) solve your problem. Because this is all still a work in progress, I do plan on adding in more functionality as time progresses. If there is anything in particular that you'd like to do with it, that you can't already, drop me a message and I'll see if it can't be added into the mix of things.
Some things that are already on the plate:
1) Allowing for multiple files to be processed that are not in the same folder
2) Allowing for the user to create a temporary run once iLogic rule that will essentially give the ability to make iLogic macros. It will simply create the rule, run the rule code, and then delete it.
The iLogic macro (item 2) is really just a personal thing that I wanted after making lots of code that creates / updates parameters in files. I don't really need the code to ever carry over with the files, so I figured it would be nice to have an automated way of running the code (that is already written, which is the important part), without cluttering up my rule browser.
I didn't look too deeply into your code yet but are you able to place External rules under a specific event trigger with your solution?
Sadly, not in any direct way. I'm actually glad that you mentioned that, as it's something I have failed to look into. However, one could always simply make an internal rule with an event trigger, that only has the function of running the external rule, by default, when the internal's event trigger goes off.
Megajerk,
Thanks for posting all of this! I look forward to giving it a try when I get a chance. I wish there was a way to merge the two posts.
Again, thanks.
@MegaJerk I know this is an old post but it seems the most relevant place.
I'm trying to add a rule through VBA but i cannot find the named propertyset. I only ever see the standard four whether i do it through the interface or try to add it in code.
On Error Resume Next Dim oPropSet As PropertySet: Set oPropSet = oDoc.PropertySets.Item("iLogicEventsRules") If Err.Number <> 0 Then Call oDoc.PropertySets.Add("iLogicEventsRules", "{2C540830-0723-455E-A8E2-891722EB4C3E}") End If Call oPropSet.Add(RuleName, BaseName & "0", BaseID) 'Call oPropSet.Add("MyRule", "BeforeDocSave" & "0", "700")
I didn't read your question correctly the first time and thought you were asking how to put a rule into an Inventor File... I'm not sure why...
Either way, I believe the problem you're running into is something that was discussed over here (https://forums.autodesk.com/t5/inventor-customization/adding-an-ilogic-rule-to-an-event-trigger-with...) in a different thread.
Essentially the property set was set to 'hidden / private' and as far as I know, there is no actual way of:
1) making it unhidden
2) finding it unless you just happen to know that it is or should be there
I'm not entirely certain why it is hidden on some files and not others, but as the post describes, you should be able to use it by calling '_iLogicEventsRules' instead of 'iLogicEventsRules'.
I hope this helps! Sorry for the late response but I don't do much Inventor Dev work any more these days as I'm too busy loving Javascript :D ๐ ๐
Hi @Anonymous. I believe Autodesk took a pointer from this project and created a new App in the Autodesk App Store called "iLogic Rule Batch Tool". If that's what you were talking about, you can check that out and see if it meets your needs.
Wesley Crihfield
(Not an Autodesk Employee)
Whoa! Thanks for posting a link to this tool because I had no idea it existed!
I'm going to add a link to it in the readme of my github repo so people can at least get something more modern
Good to see that there is something more official these days
No problem. I really appreciate all the hard work folks like you put into investigating these complicated subjects and for creating such useful tools that inspired the rest of us to rethink the possibilities in these areas.
Wesley Crihfield
(Not an Autodesk Employee)
NICE!!
I have been using code injector for 2 years and it's getting really sloooow, don't know why, but it the BEST. Hope this new tool will be faster, also I know that in 2022 you can already copy and paste ilogics, but didn't test it yet, so I don't know what happens to triggers.
Can't find what you're looking for? Ask the community or share your knowledge.