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: 

API: set an Event Trigger for an ilogic Rule in a document.

17 REPLIES 17
SOLVED
Reply
Message 1 of 18
MegaJerk
6478 Views, 17 Replies

API: set an Event Trigger for an ilogic Rule in a document.

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 😉 )

 

 



If my solution worked or helped you out, please don't forget to hit the kudos button 🙂
iLogicCode Injector: goo.gl/uTT1IB

GitHub
Tags (1)
17 REPLIES 17
Message 2 of 18
MegaJerk
in reply to: MegaJerk

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.  



If my solution worked or helped you out, please don't forget to hit the kudos button 🙂
iLogicCode Injector: goo.gl/uTT1IB

GitHub
Message 3 of 18
MegaJerk
in reply to: MegaJerk

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). 

 



If my solution worked or helped you out, please don't forget to hit the kudos button 🙂
iLogicCode Injector: goo.gl/uTT1IB

GitHub
Message 4 of 18
MegaJerk
in reply to: MegaJerk

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...

 



If my solution worked or helped you out, please don't forget to hit the kudos button 🙂
iLogicCode Injector: goo.gl/uTT1IB

GitHub
Message 5 of 18
rob.j.ross
in reply to: MegaJerk

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

____________________________
Inventor Professional 2014 64 Bit
Windows 7 Professional
NVIDIA Quadro FX 4600
Dual Intel Xeon E5540 CPUs
16GB DDR3 Ram
Message 6 of 18
MegaJerk
in reply to: rob.j.ross

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. 


  

 



If my solution worked or helped you out, please don't forget to hit the kudos button 🙂
iLogicCode Injector: goo.gl/uTT1IB

GitHub
Message 7 of 18
rob.j.ross
in reply to: MegaJerk

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?

____________________________
Inventor Professional 2014 64 Bit
Windows 7 Professional
NVIDIA Quadro FX 4600
Dual Intel Xeon E5540 CPUs
16GB DDR3 Ram
Message 8 of 18
MegaJerk
in reply to: rob.j.ross

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. 



If my solution worked or helped you out, please don't forget to hit the kudos button 🙂
iLogicCode Injector: goo.gl/uTT1IB

GitHub
Message 9 of 18
jeff_jordan
in reply to: MegaJerk

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.

Autodesk Product Design Suite Ultimate 2015 (Inventor 2015 Pro SP1, Vault 2015 Pro Update 1)
MacbookPro OSx 10.9, Boot Camp
Windows 7, 64-bit
Intel Core i7 2.6 GHz
16GB
SSDs
NVIDIA GeForce GT 750M with 2GB of GDDR5
Message 10 of 18
CadUser46
in reply to: MegaJerk

@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")

Did you find this reply helpful ? If so please use the Accept as Solution or Kudos button below.

---------------------------------------------------------------------------------------------------------------------------
Inventor 2010 Certified Professional
Currently using 2023 Pro
Message 11 of 18
MegaJerk
in reply to: CadUser46

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 &colon;D 😄 😄



If my solution worked or helped you out, please don't forget to hit the kudos button 🙂
iLogicCode Injector: goo.gl/uTT1IB

GitHub
Message 12 of 18
AMN3161
in reply to: MegaJerk

hello from 2020!

 

Anyways thank you so much for this, its extremely helpful!

Message 13 of 18
mpaul
in reply to: MegaJerk

Any Chance this still exists somewhere out there? Tried the link and it doesn't download anymore.
Message 14 of 18
WCrihfield
in reply to: mpaul

Hi @mpaul.  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

EESignature

Message 15 of 18
mpaul
in reply to: WCrihfield

OMG, you are a lifesaver! this is perfect! One of my designers used old templates for 3 months with hundreds of parts that I now don't have to beat him for! Thanks again!
Message 16 of 18
MegaJerk
in reply to: WCrihfield

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



If my solution worked or helped you out, please don't forget to hit the kudos button 🙂
iLogicCode Injector: goo.gl/uTT1IB

GitHub
Message 17 of 18
WCrihfield
in reply to: MegaJerk

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

EESignature

Message 18 of 18

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.

Manuel Campos Costa

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

Post to forums  

Autodesk Design & Make Report