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: 

add a rule to the event by a iLogic rule

14 REPLIES 14
SOLVED
Reply
Message 1 of 15
k.dossantosFGLW2
664 Views, 14 Replies

add a rule to the event by a iLogic rule

Hi Everyone,

Do someone has a rule to add a rule on the before save document event trigger ?

 

Thanks

14 REPLIES 14
Message 2 of 15

Hi @k.dossantosFGLW2.  Yes, this may be possible, but we would need to know more about this task from you to be sure.  But it can be a relatively complex process.  Have you searched within this forum yet for what you want?  When I search this forum for that topic, I get many results.  I have been involved in many of those discussions.  There is a lot of good information among those other forum posts about this topic, many of which have been solved, and contain example codes as solutions.

Which tab within the Event Triggers dialog do you want to add this rule within (All Documents, Parts, Assemblies, Drawings, This Document)?

Is the rule that you want to add to the Event Triggers an internal rule (saved within an Inventor document) or an external rule?

Wesley Crihfield

EESignature

(Not an Autodesk Employee)

Message 3 of 15

Yes I have searched but not enought as it seems.
I want to add an internal rule inside the document currently opened

Thank you for your help
Message 4 of 15

OK @k.dossantosFGLW2.  I will attach a text file to this response which will contain some code that you can use as an iLogic rule.  It is rather long, so posting it within an attached text file is more convenient for both of us.  Review the code before running it.  This code could be used either as an external, or internal iLogic rule itself, and can also be used to add either an internal, or external iLogic rule to the Event Triggers dialog, on the 'This Document' tab only, and is currently set-up for that one specific event 'Before Save'.  Not sure how familiar you are with this process, but each different event has its own 'internal' name that is different from what you see within the Event Triggers dialog.  And each different event has its own range of PropID values that must be used just for that event.  I will also attach my Excel file containing the chart/table of what those internal event names are and what their PropID ranges need to be.  This data should be accurate for the initial release of Inventor version 2024, but might not be 100% inclusive for later updates of Inventor.  Give these a try, and let me know how it works for you.

Wesley Crihfield

EESignature

(Not an Autodesk Employee)

Message 5 of 15

Hi @k.dossantosFGLW2.  Here is another version of that code that includes a an additional custom Function routine.  In this version, after you have specified the name of the iLogic rule you want to add into the Event Triggers, it will run that added custom Function, which will prompt you to select one of the available events from a list.  Then that function returns a two factor piece of data to the main routine, which will contain that internal event name, and the PropID that should be used with that event.  Those two values are used to set the values of the other two variables for you, so that you do not need to guess or look up what the proper name/spelling should be, or what values to use for the PropID.  Also, if you do not want to use that added routine, it is nice to have it available below as a reference for which names and values are available, in case you do not want to find the Excel file and review that every time.  I also have a custom Function for allowing user to select an external iLogic rule that I use in some situations, but it is longer, and more complex than the one for choosing an internal rule from the current document.  Plus, I usually do not put all these routines into one iLogic rule, but instead may have those other routines in other rules, then call those other rules to run, so I am not duplicating code.

 

There are several ways this type of overall routine could be laid out to work.  Sometimes including some user interaction can make the code more dynamic or easy to use, while other times, less or no user interactions may be wanted.  But in a case like this, if there is no user interaction, then all those specifications must be hardcoded into the rule, and the code must be edited each time you want to use different values, so there is a balance to it, and it all depends on your needs.

 

Wesley Crihfield

EESignature

(Not an Autodesk Employee)

Message 6 of 15

Thank you for all the explanation.
Message 7 of 15

@WCrihfield

 

Excellent rule, but is a little more involved than I need, and as I am not a coder, I do not know where to begin to modify this.

 

Can it be simplified to add just a few pre-determined external rules (will be hard-coded, not selected from a list) to fire on the Before Save event?

 

i.e. The code will:

  1. Add rule 1 to run 1st
  2. Add rule 2 to run 2nd
  3. Add rule 3 etc...

Thank you for any help...

 

Message 8 of 15
WCrihfield
in reply to: b.mccarthy

Hi @b.mccarthy.  I created a different iLogic rule that should meet your needs better.  I added tons of comments in there to help you understand everything that is going on.  It is in the attached text file.  You will need to edit the names of the external iLogic rule names in Lines 10, 11, & 12.  If you need to add more external rule names, just duplicate one of those 3 Lines, then change the rule name in the new line to what you want.  Or, if you need fewer rule names, just delete one of those 3 Lines, or add an apostrophe (') at the left (start) of one of those lines of code to 'comment it out'.  You should not need to edit anything else in the code.

Let me know how this works for you.

Wesley Crihfield

EESignature

(Not an Autodesk Employee)

Message 9 of 15
WCrihfield
in reply to: b.mccarthy

Hi @b.mccarthy.  I should have tested that one more before posting it, because I found some mistakes in it later.  Attached is an updated version of it, that I did a lot more trial & error testing on, and it seems to be working good for me.

Wesley Crihfield

EESignature

(Not an Autodesk Employee)

Message 10 of 15
b.mccarthy
in reply to: WCrihfield

@WCrihfield 

 

Sorry for the late response... Fires... Many fires...

 

Thank you for this, and it works perfectly!

 

This is a big ask, but can it be modified to run at an assembly level?

 

TIA

Message 11 of 15

As in iterate through all parts in an assembly and add the rules...

Message 12 of 15
WCrihfield
in reply to: b.mccarthy

Hi @b.mccarthy.  Yes, that should not be much trouble.  However, it is a typical Monday morning for me at work, so there are a few things I need to catch up on after having the weekend off, so I will report back later today, hopefully with the updated code example.  The main thing that will need to happen is transferring the block of code that will get repeated many times down into a separate Sub routine, while keeping the custom stuff that only needs to be specified once up in the 'Main' routine, or between routines.

Wesley Crihfield

EESignature

(Not an Autodesk Employee)

Message 13 of 15

@WCrihfield

 

Thank you. I really appreciate your help...

Message 14 of 15
WCrihfield
in reply to: b.mccarthy

Hi @b.mccarthy.  Here is something you may be able to use.  I took what you said in Message 11 literally (all parts in an assembly), which I understood as [only run this process on the part documents, not on any sub assembly type documents], so I hope that was you intent.  If not, and you want it to run on all referenced documents, not just parts, then that can be changed by getting rid of Lines 23 & 24.  Also, I was not sure if you wanted the routine applied to the main assembly itself, or only its referenced documents, so, I have a line of code in there (Line 18) commented out, which would be running the process on the main assembly document itself, before running it on the referenced documents.  I did not incorporate a document type check at the start of this rule, so it could be ran on an assembly, part, or drawing.  However, if ran on a Part, you would want to uncomment Line 18.  I was not sure how to handle that situation.  We could add some additional design intent in there, such as...if the 'main' document is a part, then run that line, else if it is an assembly or drawing, then do not run it.  As before, you will need to change Lines 13-15 as needed, or add/delete some lines in that area for more or less external rule names.  There is no 'feedback' designed into this code process, but I left the comments in there.

Wesley Crihfield

EESignature

(Not an Autodesk Employee)

Message 15 of 15
b.mccarthy
in reply to: WCrihfield

@WCrihfield 

 

Thank you for this. It works great!!

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

Post to forums  

Technology Administrators


Autodesk Design & Make Report