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: 

Adding an iLogic Rule to an Event Trigger with VBA

45 REPLIES 45
SOLVED
Reply
Message 1 of 46
ccoomes
11719 Views, 45 Replies

Adding an iLogic Rule to an Event Trigger with VBA

I have done lots of searching and found nurmeous posts about how to get the API to add an iLogic Event Trigger but I cannot find the exact code on how to do it.

 

My knowledge of VBA is limited and I am now stuck.  This is one of the last little pieces of code that we need.

 

Is there a Simple way to add an Ilogic Rule (External or Internal) to an event trigger with a VBA Macro or iLogic Rule?

 

I would like to automate adding an iLogic rule to an Event Trigger when we update our old drawings.

 

The details of the Rule I am trying to call is as follows:

 

Rule Name = Save On Close Commands

Event = Before Close

 

We currently have Inventor 2013 and 2014.  If it is not possible in 2013, is it possible in 2014?

 

If someone could please post the text needed to get the Rule Added to the Event Trigger it would be greatly apprcaited.

 

Thanks in advance.

45 REPLIES 45
Message 21 of 46
bennywise578
in reply to: bennywise578

Discovered that the Property ID for Drawing View Change is 1800 (atleast for Inventor 2013). Anyone confirm this?

 

 

Message 22 of 46
NL-Laurens
in reply to: ccoomes

Hi Bennywise,

 

I can confirm that the Property ID for Drawing View Change is 1800 for Inventor 2012.

 

Also I want to warn everybody that you could get strange warnings when you allready have a faulty propertyID for Drawing View Change. Try to delete all your iLogic and retry with the propertyID set to 1800. All troubles should be solved.

Message 23 of 46
MegaJerk
in reply to: bennywise578

I will make a note of this.

Sorry for the non-updates, but I'm working with C#, and decided that my first project would be re-creating the code injector using that language. Sadly, before that starts, I need to do everything under the sun for work / home 😕


Thanks for the heads-up!



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

GitHub
Message 24 of 46
AlexFielder
in reply to: MegaJerk

Maybe I have missed it in this thread but how simple a modification to the source would it be to not only inject the ilogic code into these files but run it as well.

 

The reason I ask is that I have ~100 drawings which I need to run a simple piece of ilogic against; the ilogic code simply pulls the description from the part/assembly into the drawing iproperties and I'd rather not have to do it manually.

 

Unless someone can suggest another faster way I haven't thought of?

Message 25 of 46
Robert..F
in reply to: AlexFielder

I believe this is already possible through the code provided by megajerk. See the details here:

 

http://beinginventive.typepad.com/being-inventive/2012/02/injecting-ilogic-code-and-ilogic-event-tri...

Message 26 of 46
AlexFielder
in reply to: Robert..F

Ah, so if I had set the rule to "run before save" then it would have done it for me- I had in the meantime figured out my own method:

 

  1. Check files out of Vault
  2. Run Tool to insert rule to trigger "on file open"
  3. reopen all files in inventor so the rule fires.
  4. closeall files saving one by one.
  5. use the task scheduler to check all files back in.

I shall try it again next time I need to sync iproperties using the "trigger before save" method.

 

Thanks.

 

🙂

 

Message 27 of 46
ccoomes
in reply to: bennywise578

If this helps anyone, please find attached the module text we use to add Event triggers to old and existing Inventor Drawings.

 

I basically used the Excellent code supplied from MegaJerk and adjusted it to suit.

 

The Main Difference I made was to use his code to add an event trigger that runs an external iLogic Rule.

 

I did this as you have to use the Character codes and not the actual characters to get them to appear in the iLogic Rule.

See the RuleText Line for clarification...

 

This means that you only have to modify the External iLogic rule instead of adding text to the VBA Code.

This can then be easily done us the iLogic Editor...

 

I did have to turn off the Debug.Print Line on the AddOnCloseEventTriggers() as it was firing as soon at the Event Trigger was added.

Please note that it was NOT Firing, and then all of a sudden it starting firing when it was added....

 

Hope this helps.

Message 28 of 46
tfreed
in reply to: ccoomes

 

Hello,

 

Inventor 2015

 

I was trying to use this code that has been passed around in the thread to add an external rule to an event trigger ("BeforeSave") in our own VBA Macro.

 

The problem that I am having is that on a new dwg that I have set up to work property, with the rule on a event trigger, the 5th property set called "iLogicEventsRules" (which the "Rule Injector" says defines the event triggers) does not exist and I can't seem to find where the event trigger rules are defined.

 

In my visual studio, I can tell there is a "Beforedocsave" event enumerator, but I can't tell what commands use that enumerator.

 

I even tried the "Rule Injector." On one dwg, it added the event, but it didn't show up in the "event trigger" list thru the Manage>Event trigger button. (which scares me)

On another drawing, the rule injector gave an error message about not being able to add the "event trigger"

 

I am looking for one of the following:

1. Code to show how to add an external rule to an event trigger.

2. the command in the object model to add an event trigger.

 

I have included a sample inventor dwg with the event trigger set up the way I would like as well as the rule.

Message 29 of 46
adam.nagy
in reply to: tfreed

Hi,

 

Here is a blog post that should help:

http://adndevblog.typepad.com/manufacturing/2015/01/add-external-ilogic-rule-to-event-trigger.html

 

Cheers,



Adam Nagy
Autodesk Platform Services
Message 30 of 46
johnster100
in reply to: ccoomes

Hi,

Does anyone know how you would use this code to get the existing triggers in a document so that the document rules and triggers can be copied to a new file.

 

thanks,

John

Message 31 of 46
DRoam
in reply to: ccoomes

All,

 

While the Injector tool is handy, it still requires manual injection of the desired rules. Also, the code provided by MegaJerk seems fantastic, but it's very, very involved for something that shoud really just take a couple lines of code.

 

So, I've posted a request in the IdeaStation for just that. Please cast a Kudo if you'd like the ability to check and add to the Event Triggers using built-in iLogic functions. The idea is located here: Add iLogic functions for handling Event Triggers

 

Thanks!

Message 32 of 46
DuduHarel7605
in reply to: DRoam

Hii all,

I've tried this iLogic external rule to add an internal rule (name "Rule1") to Event Trigger and it worked!

 

Dim doc As Document
doc = ThisApplication.ActiveDocument
Dim customPropSets As PropertySets
customPropSets = doc.PropertySets
Dim customPropSet As PropertySet
customPropSet = doc.PropertySets.Item("_iLogicEventsRules")
customPropSet.Add("Rule1", "BeforeDocSave0", 700)

 

note thet there is no "Set" or "Let" at  iLogic rules

 

David

Message 33 of 46
MegaJerk
in reply to: DuduHarel7605

Congrats, D Harel!

Just be careful if you try to do more than one rule as the iPropertie's ID will need to increment by one from the highest ID in that Triggers set.

So, something like -

customPropSet.Add("Rule1", "BeforeDocSave0", 700)
customPropSet.Add("Rule2", "BeforeDocSave0", 700)


Would be wrong

I should also say that, currently the code injector has been updated to correct a last of the few glaring errors that existed in the last version. It's available in the links down there in my signature. Once I complete some classes I'm in the middle of, I should have a much needed improved version out for release.

Good to see you making progress, and remember to ask questions if you get stuck!

 



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

GitHub
Message 34 of 46
zdhrichard
in reply to: DuduHarel7605

Great Code!

But if  I want to remove one rule from Event Trigger (After Open Document), what is the code?

If the rule is external rule, will it work?

I mean I manually put one external rule and using Event Trigger (After Open Document) to run it automatically, I want after run this rule, it could be removed by iLogic code in this external rule.

Is it possible?

Rich

Autodesk Inventor Professional 2018 (64 Bit Edition)
Build: 284, Release 2018.3
Windows 7 Professional Service Pack 1
Intel(R) Xeon(R) CPU E5645
12.0 GB Memory
Message 35 of 46
ThatWorksForMe
in reply to: MegaJerk

The code works perfect, thanks for that.

But I have a problem when I run the code.

I make a call on the "VerifyTrigger" function like this:

 Call VerifyTrigger(oDoc, "1_AfterDocNew", "New Document")
Call VerifyTrigger(oDoc, "2_AfterDocOpen", "After Open Document")
Call VerifyTrigger(oDoc, "3_BeforeDocSave", "Before Save Document")
Call VerifyTrigger(oDoc, "4_AfterDocSave", "After Save Document")
Call VerifyTrigger(oDoc, "5_DocClose", "Close Document")
Call VerifyTrigger(oDoc, "6_AfterAnyiPropertyChange", "iProperty Change")
Call VerifyTrigger(oDoc, "7_AfterDrawingViewsUpdate", "Drawing View Change***")

The code creates for every ilogic rule the right rule, but the last rule is not set.

It is always empty. Any idea what this colud be?

Unbenannt.PNG

PDM/CAD Administrator
Using Inventor/Vault 2022.2
Message 36 of 46
MegaJerk
in reply to: ThatWorksForMe

Unfortunately I haven't done a lot of personal work using Inventor for about a year and a half (having transitioned to a department - away from Design), so I can't say 100% what the problem is. 

However, I recommend first manually adding the eventTrigger in question to an iLogic rule, and then while in VBA set a variable to be the value of the iProperties for the Event Triggers. This should let you explore the location of the manually added rule, and give you a better idea of how it should be added. 

It may just be that the math for adding it was off (All rules added to that iProperty set must have an id that falls within a particular range that indicates their position in the 'stack' (how they will be queued / called), and I'm not sure how that may have changed over the years, etc. etc.), or the name was wrong. 

Sorry that I cannot give you any more detailed help at the moment, but this should get you going in the right direction I think! 



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

GitHub
Message 37 of 46
MegaJerk
in reply to: ThatWorksForMe

**Accidental Double Post...**



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

GitHub
Message 38 of 46
ThatWorksForMe
in reply to: MegaJerk

Hey MegaJerk,

thanks for our hint. I figured out that the property id for "Drawing View Change***" isnt any longer 1500, its 1800 now.

If I change the id, it will work. But I found another problem.

The rules are put to the right triggers, but they wont be called on "document save" or any other action.

Maybe its the same problem width the id range. I dont know.

I will try to find the problem

PDM/CAD Administrator
Using Inventor/Vault 2022.2
Message 39 of 46
NL-Laurens
in reply to: ccoomes

To All,

 

Here is a quick reference to all property id's:

 

AfterDocOpen, Property-id startkey: 400, use: ipt/iam/idw/dwg
DocClose, Property-id startkey: 500, use: ipt/iam/idw/dwg
BeforeDocSave, Property-id startkey: 700, use: ipt/iam/idw/dwg
AfterDocSave, Property-id startkey: 800, use: ipt/iam/idw/dwg
AfterAnyParamChange, Property-id startkey: 1000, use: ipt/iam/idw/dwg
PartBodyChanged, Property-id startkey: 1200, use: ipt
AfterMaterialChange, Property-id startkey: 1400, use: ipt
AfterAnyiPropertyChange, Property-id startkey: 1600, use: ipt/iam/idw/dwg
AfterDrawingViewsUpdate, Property-id startkey: 1800, use: idw/dwg
AfterFeatureSuppressionChange, Property-id startkey: 2000, use: ipt
AfterComponentSuppressionChange, Property-id startkey: 2200, use: iam
AfterComponentReplace, Property-id startkey: 2400, use: iam
AfterDocNew, Property-id startkey: 2600, use: ipt/iam/idw/dwg

Message 40 of 46
ThatWorksForMe
in reply to: NL-Laurens

Thanks NL-Laurens for the summary.

 

I found out that the problem is more heavy weight then I thought.

Inventor seems to handle local and external rules different.

If I fill the trigger "before save document" manually with a local rule (example: "TestRule") it will work whithout problems.

If I fill the trigger by vba automatically with the same local "TestRule" it will work also.

 

But if I delete the local rule and create an external rule named "TestRule" the problems will start.

If I fill the trigger "before save document" manually with a external rule (example: "TestRule") it will work whithout problems.

If I fill the trigger by vba automatically with the same external "TestRule" it wont work and the error message says that there is no rule named "TestRule".

 

If I create a local and an external rule with the same name, the local rule is prefered.

 

Maybe somebody could check if there are the same issues on an other system.

PDM/CAD Administrator
Using Inventor/Vault 2022.2

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

Post to forums  

Autodesk Design & Make Report