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: 

Trigger an External Rule after a parameter change

7 REPLIES 7
Reply
Message 1 of 8
juandv30
1125 Views, 7 Replies

Trigger an External Rule after a parameter change

Hello everyone...

 

I´ve been trying to trigger an external rule when I change any parameter in an ipt file.  I founded in Autodesk User Group International's website the following:  

"Notes on External Rules: External Rules do not run automatically in response to parameter changes. If you need this functionality, you will have to code it yourself. Check out ‘ModelingEventsSink.OnParameterChange Method’ in the developer help."

 

To see the full article:  

http://www.augi.com/library/playing-by-the-ilogic-rules

 

After that, I went to the developer help but I couldn´t understand how to write the code to run the external rule after changing any of the existing parameters in my model.  I already tested my code as an internal rule and use the trigger "Any model parameter change" and it works fine.

 

Can anybody help sending me a sample code so I can adapt it to my rule?  

 

Thanks

Juan Velez

 

7 REPLIES 7
Message 2 of 8
rjay75
in reply to: juandv30

An easy way to have an external rule run when an parameter changes is to have two rules. Your external rule, and an internal helper rule.

 

In your external rule any place you use the parameter it must referenced as Parameter("parameterName").

 

In your internal rule reference the parameter as just parameterName.

 

Your helper rule references the parameters so it will run when the parameters are changed and it runs the external rule.

 

For example:

 

External Rule:

Parameter("doubleLength") = Parameter("length") * 2.0 ul

 

 

Internal Helper Rule:

value = length

iLogicVb.RunExternalRule("ExternalRuleName")

 

In this example if the value of length changes it will run the external rule. In the external rule any parameters can be used.

Message 3 of 8
juandv30
in reply to: rjay75

Hi rjay75.

 

I just tested your suggested solution and works fine

 

Unfortunately I am planing to use the external rule to write and edit a bunch of parameters in thousands of existing files.  The solution you suggested works fine for a new file where the internal rule can be created.  I does not seem to be practical for running the external rule in files created previously.

 

The idea is to open each old file, and have the capability to edit some user parameters using global forms and external rules.  I have several parameters that depend from some other multivalue parameters.  What I would like to happen is the dependant parameter update automatically once a multivalue option is selected without using an update button.

 

Thank a lot

Message 4 of 8
Vladimir.Ananyev
in reply to: juandv30

You may consider the following workaround.
You may remember the initial values of your multi-value parameters when your external rule starts. 
In the end you may compare the current values with the initial values, and then implement appropriate actions.

Not too elegant but this should work.


Vladimir Ananyev
Developer Technical Services
Autodesk Developer Network

Message 5 of 8
mrattray
in reply to: juandv30

The iLogic code injection tool by MegaJerk could be useful to you. Search for it here.

Mike (not Matt) Rattray

Message 6 of 8
juandv30
in reply to: mrattray

Hello Mike,

 

Yes, it shure does work!!  I already tried it. But this tool is only good for transfering internal rules masively to a set of files,but it does not transfer the triggers for those rules.  You will have to configure triggers manually for each file.  So by the end of the day, neither the internal and external rules fire after any parameter change.  The issue persists!!

 

My only hope is to be able to configure the trigger as per Autodesk User Group International's website:  

 

"Notes on External Rules: External Rules do not run automatically in response to parameter changes. If you need this functionality, you will have to code it yourself. Check out ‘ModelingEventsSink.OnParameterChange Method’ in the developer help."

 

Thanks

Message 7 of 8
mrattray
in reply to: juandv30

Did you have the latest version? I'm pretty sure he added the ability to add the "injected" rules to the event triggers somewhat recently.

 

Edit:

Here's the link: http://beinginventive.typepad.com/being-inventive/2012/02/injecting-ilogic-code-and-ilogic-event-tri...

It does support adding triggers.

Mike (not Matt) Rattray

Message 8 of 8
juandv30
in reply to: mrattray

Hi Mike,

 

Yes, you are right!!!  Somehow I didn't see the check boxes for event triggers in the up right corner of the dialog.

 

I will use this method from now on.

 

Thanks a lot

 

Juan Velez

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

Post to forums  

Autodesk Design & Make Report