Force external iLogic rule to run in component it was triggered from

Force external iLogic rule to run in component it was triggered from

DRoam
Mentor Mentor
3,140 Views
6 Replies
Message 1 of 7

Force external iLogic rule to run in component it was triggered from

DRoam
Mentor
Mentor

I have a part which is set to run a specific external iLogic rule before the part is saved. The external rule creates a parameter in the part if the parameter doesn't already exist, among other things.

 

The problem I'm having is, if I do a save on an assembly that contains the part, then when I save, Inventor runs the external rule per the save trigger but it executes the code on the active assembly, not on the part that contained the "run this rule when I save" trigger. As a result it creates the parameter in the assembly rather than the part.

 

I need to force Inventor to execute the rule's code on the part it was triggered by, rather than the active document.

 

It's my understanding that local rules work this way. If I have a trigger in the part to run a rule stored within the part upon save, then even if I save the part from the assembly level, Inventor will recognize the rule resides within the part and execute the code on the part. But in this case, because there are specific reasons for the rule being external rather than local, I need to find a way for triggered external rules to function the same way. How can I do this?

Accepted solutions (1)
3,141 Views
6 Replies
Replies (6)
Message 2 of 7

BrandonBG
Collaborator
Collaborator

Two things you could try running at the assembly level:

 

iLogicVb.RunExternalRule(oComponentOccurrence, "external rule name")

I can't remember if that syntax works or not. 

 

Or,

oComponentOccurrence.Edit()

iLogicVb.RunExternalRule("external rule name")

oComponentOccurrence.ExitEdit(63746) 'exit to Parent

Brandon

0 Likes
Message 3 of 7

DRoam
Mentor
Mentor

Hi Brandon, thanks for the reply. The probelm with that approach is that the rule has to be triggered from the part itself, because it has to be triggered as an Event Trigger when the part is saved. This way, it always and only runs if the part has been changed, which is what I need.

 

All: Is there a way I can have an internal rule grab code from an external rule (or even some other external source, like a text file), and execute that as part of the internal rule? (I know I can trigger an External rule from an internal rule, but I assume it would still execute as an external rule, and act on the active document, rather than the document it was triggered from. But if I could have the internal rule itself execute the code...)

0 Likes
Message 4 of 7

mcgyvr
Consultant
Consultant

Sounds like an issue with your specific code..

I have numerous parts with an external rule that runs from an event (save) triggers. These rules do NOT effect the iam they are placed in at all..

 

 

 



-------------------------------------------------------------------------------------------
Inventor 2023 - Dell Precision 5570

Did you find this reply helpful ? If so please use the Accept Solution button below.
Maybe buy me a beer through Venmo @mcgyvr1269
Message 5 of 7

DRoam
Mentor
Mentor

Oh ok, interesting. Do any of those external rules create User Parameters if they're missing?

0 Likes
Message 6 of 7

DRoam
Mentor
Mentor

I think I might have found the issue. Here is the line of code that creates the parameter if it's missing:

 

oParameter=ThisApplication.ActiveDocument.ComponentDefinition.Parameters.UserParameters.AddByExpression("Schedule", myparam, "ul")

You can see it's accessing the active document, so if I'm in my assembly and do a save, and my part gets saved, the assembly will be the active document so the parameter will be added to the assembly.

 

So the question is, is there a way to create a user parameter within the document that a rule is being executed on, rather than the active document? I'll do some looking but if you know the answer that would be great!

0 Likes
Message 7 of 7

DRoam
Mentor
Mentor
Accepted solution

@mcgyvr wrote:

Sounds like an issue with your specific code..

I have numerous parts with an external rule that runs from an event (save) triggers. These rules do NOT effect the iam they are placed in at all.. 


Got it! All I had to do was replace "ThisApplication.ActiveDocument" with "ThisDoc.Document", and now the code is executed on the document it's triggered from (the part), rather than the active document (the assembly). Thanks for getting me on the right track, @mcgyvr!