Using iLogic to create an event trigger not working (for me)

Using iLogic to create an event trigger not working (for me)

gcoombridge
Advisor Advisor
1,606 Views
12 Replies
Message 1 of 13

Using iLogic to create an event trigger not working (for me)

gcoombridge
Advisor
Advisor

Hi All,

 

(Inventor 2021.2)

I have been referring to this post: Solved: Ilogic to add ilogic to event triggers - Autodesk Community - Inventor which @Sergio.D.Suárez solved in 2019. I have created a part file from which I will run a rule that will:

 

  • Select a solid body
  • Open a new part
  • derive the solid body into it
  • create some parameters
  • write an (internal) ilogic rule in the part to refer the parameters back to the derive 'master'
  • create an event trigger to run the rule when any part model geometry changes (based on master changes)/before save.

This has been surprisingly successful given my modest ilogic abilities. The only thing not working correctly is the last step. The event trigger is created and applied in the new part, no errors are produced - it just doesn't seem to function properly! Interestingly the before save trigger does work as expected, just not the model geometry change.

 

I'm having difficulty finding any info on this in the API help... I have re-created the problem with two sample parts below. Running the event trigger rule in DerivePartA.ipt will create the trigger in the box but it doesn't work when geometry is changed in DeriveBaseA.ipt. Delete this and manually add the trigger and it works! 

 

Any thoughts?

 

 

'This sub creates an event trigger to make sure the transfer is always updated
Sub Events
On Error Resume Next
	Dim EventPropSet As Inventor.PropertySet
	EventPropSet = GetiLogicEventPropSet(ThisApplication.ActiveDocument)
	EventPropSet.Add("Iproperties (Automatic)", "PartBodyChanged", 1200)
	EventPropSet.Add("Iproperties (Automatic)", "BeforeDocSave", 700)

'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

InventorVb.DocumentUpdate()
	

End Sub

'***************************************************************************************************************************

'part of the event trigger
Function GetiLogicEventPropSet(cDocument As Document) As Inventor.PropertySet
	On Error Resume Next
		iLogicEventPropSet = cDocument.PropertySets.Item("iLogicEventsRules")
		
		If iLogicEventPropSet Is Nothing Then
			iLogicEventPropSet = cDocument.PropertySets.Item("_iLogicEventsRules")
		End If
		
		If iLogicEventPropSet.InternalName <> "{2C540830-0723-455E-A8E2-891722EB4C3E}" Then
			Call iLogicEventPropSet.Delete
			iLogicEventPropSet = cDocument.PropertySets.Add("iLogicEventsRules", "{2C540830-0723-455E-A8E2-891722EB4C3E}")
		End If
		
		If iLogicEventPropSet Is Nothing Then
			iLogicEventPropSet = cDocument.PropertySets.Add("iLogicEventsRules", "{2C540830-0723-455E-A8E2-891722EB4C3E}")
		End If
		
		If iLogicEventPropSet Is Nothing Then
			MsgBox ("Unable to create the Event Triggers property for this file!", , "Event Triggers Not Set")
			Err.Raise(1)
			Exit Function
		End If
	On Error GoTo 0
	
	Return iLogicEventPropSet
End Function

 

 Thanks,

Glenn

Use iLogic Copy? Please consider voting for this long overdue idea (not mine):https://forums.autodesk.com/t5/inventor-ideas/string-replace-for-ilogic-design-copy/idi-p/3821399
0 Likes
Accepted solutions (2)
1,607 Views
12 Replies
Replies (12)
Message 2 of 13

gcoombridge
Advisor
Advisor

I've also test this with 2019.4.3 and have the same issue

Use iLogic Copy? Please consider voting for this long overdue idea (not mine):https://forums.autodesk.com/t5/inventor-ideas/string-replace-for-ilogic-design-copy/idi-p/3821399
0 Likes
Message 3 of 13

WCrihfield
Mentor
Mentor
Accepted solution

I also did a lot of work with the Event Triggers via iLogic code.  I have created some contribution posts about it you may find helpful.

How To: "Unhide" the "Hidden" Event Triggers iProperties PropertySet using an iLogic rule 

Add an iLogic Rule to an Event Trigger Using an External iLogic Rule 

Copy All iLogic Rules & Event Triggers From One Document To Another Using An External iLogic Rule 

 

 

If this solved your problem, or answered your question, please click ACCEPT SOLUTION.
Or, if this helped you, please click 'LIKE' 👍.

If you have time, please... Vote For My IDEAS 💡and Explore My CONTRIBUTIONS

Inventor 2021 Help | Inventor Forum | Inventor Customization Forum | Inventor Ideas Forum

Wesley Crihfield

EESignature

(Not an Autodesk Employee)

Message 4 of 13

gcoombridge
Advisor
Advisor

Thanks @WCrihfield - those links are very useful. This is definitely quite a hard area to find documentation about! Looking over them, aside from the name not including the propID, the gist is very similar to the link above. Establish if the file has the property set, unhide it and add a property to the specific bounds of the ID range.

 

Whatever I do I don't seem to be able to create the part geometry change trigger with code and have it operate correctly however. It appears in the trigger dialogue box when the code is run but does not function as it should. If I had more confidence in my coding ability I would declare it was a bug. However, before save as in your example works fine (I was using that also). What I'm trying to do is update a text parameter with the member name of a structural section i.e. "300PFC". The geometry change trigger is a much more immediate way to keep these values in agreement...

Use iLogic Copy? Please consider voting for this long overdue idea (not mine):https://forums.autodesk.com/t5/inventor-ideas/string-replace-for-ilogic-design-copy/idi-p/3821399
0 Likes
Message 5 of 13

WCrihfield
Mentor
Mentor

   Curious.  You said your code is adding your (update the text parameter) rule to the correct event in the target document's Event Triggers dialog OK, but then that trigger doesn't seem to be working correctly, right?  Have you tried adding your (update the text parameter) rule to the Event Triggers manually, and see if the trigger works any differently than when done by code?

   Are you sure your target rule, the one that writes the name of a "structural section" to a text parameter, isn't being fired, or is it possible it just isn't doing its job correctly, for some reason?  Exactly what are you doing with this 'structural section' that is supposed to be causing the event to fire?

Wesley Crihfield

EESignature

(Not an Autodesk Employee)

0 Likes
Message 6 of 13

gcoombridge
Advisor
Advisor

Yes the trigger is created in the dialogue box but does not function when there is a change in part geometry. If I delete this and add the trigger manually it does function as you would expect. Interestingly the before save trigger does work when generated by code. It does seem like a bug...

 

The point of the whole business is to make a multi-part solid as a master file and then use code to derive out solids (structural sections), write a rule in the new part that creates a text parameter link with the section type back to the master (as text params cannot travel through the derive process). It is an alternative to frame generator for more fabricated sections...

 

The code is being run from within the master part which generates a new file but I have tested this with the rule being based inside the new file also. The new file is has no existing triggers in the template. When I change the size in the master and refresh the child part it should fire the rule and update the text param.

 

I don't want to take up any more of yours time this close to Christmas but I'll bump the thread again in Jan. I'd be interested to know if you or anyone else finds the same behavior when they do the same thing...

 

Thanks,

Glenn

 

 

Use iLogic Copy? Please consider voting for this long overdue idea (not mine):https://forums.autodesk.com/t5/inventor-ideas/string-replace-for-ilogic-design-copy/idi-p/3821399
0 Likes
Message 7 of 13

j.haggenjos
Advocate
Advocate

I have had issues with creating event trigger before. I could use some of the trigger. However, I never managed to create an "After Doc Open" trigger, potentially due to security issue. I had to find a way to work around it by using different kind of trigger.

 

With what you wrote, I can see four potential way to work around your trigger issue:

 

@gcoombridge wrote:
The new file is has no existing triggers in the template. When I change the size in the master and refresh the child part it should fire the rule and update the text param.


  • Create a template that does contain the trigger you need. If the rule is created dynamically based on the master parameter, you can have a rule on the trigger inside your template that will in turn fire your dynamic rule.

 

 

iLogicVb.RunRule("RuleToTrigger")

 

 

 

  • How are you triggering the refresh in the child part? If you have a rule in the master that push the changes/refreshes the component, you could trigger the rule right after you pushed the changes in the different childs component. The iLogicAutomation interface allows you to run rules inside other document:

 

Dim iLogicAutomation As Object = ThisApplication.ApplicationAddIns.ItemById("{3bdd8d79-2179-4b11-8a5a-257b1c0263ac}").Automation

iLogicAutomation.RunRule(Document, RuleName)
iLogicAutomation.RunExternalRule(Document, RuleName)

 

  • Parameter that are explicitly named in a rule will trigger that rule when they change. If the parameter that will trigger has a predefined name, you can do something like this

 

trigger=ParameterTrigger1
trigger=ParameterTrigger2

 

Now if ParameterTrigger1 or ParameterTrigger2 is changed in the part, it will fire the rule containing the trigger (only work with internal rules)

 

  • To have more control over which piece of code runs when and where. Consider creating an AddIn or using the VBA tools integrated in Inventor. This is a longer term solution but in case you are considering to make complex automation, you will save yourself some hair pulling trying to work around the limitation of iLogic.
Message 8 of 13

WCrihfield
Mentor
Mentor

@j.haggenjos  FYI:  There is a much simpler and shorter way to get the iLogic Automation Interface object within an iLogic rule.

Dim oAuto As IiLogicAutomation = iLogicVb.Automation

 Also, good point about using the name of local parameters in a local iLogic rule to trigger the rule to run whenever that parameter changes.  That's an oldie, but goodie. 😉

Wesley Crihfield

EESignature

(Not an Autodesk Employee)

0 Likes
Message 9 of 13

gcoombridge
Advisor
Advisor

@j.haggenjos to be honest I can probably live with before save as a trigger. I am at the 95% mark with this the part geometry change trigger takes it to 100 in terms of robustness. There is nothing in the child part that will trigger the rule to run by itself, the geometry is derived through but the parameters cannot be, as they are text, not numerical parameters.

 

To address each of your points:

  • Creating a new template with a 'rule to trigger' is a really good idea. Because the child part rule is written by the derive rule it won't be possible to trigger that rule but the rule name is static so the separate rule will solve it.
  • The refresh is triggered when the geometry of the part is changed and the new part is updated, either in a subsequent assembly or in the part. The change isn't being pushed as such with code - just the automatic derived part relationship. By this arrangement the deadbeat parent file doesn't know who it's children are... 
  • The parameters are explicitly named, but as text and unrelated to any geometry they can't change without help.
  • The add-in/VBA suggestion is a good one too, I'll get onto that when I have some time.

Ultimately I am keen to see if anyone else has used a part geometry change trigger created with ilogic successfully, or this is a bug. When this trigger is created manually it functions perfectly and does exactly what I need...

Use iLogic Copy? Please consider voting for this long overdue idea (not mine):https://forums.autodesk.com/t5/inventor-ideas/string-replace-for-ilogic-design-copy/idi-p/3821399
0 Likes
Message 10 of 13

j.haggenjos
Advocate
Advocate
Accepted solution

Reading your reply I just thought of something in case you go with the new template already containing  the trigger route.

 

Instead of triggering a rule. You could:

 

ThisDoc.Document.Save

 

Which will give your template an "auto-save" behavior. This way, you can keep your current code that creates the trigger before save and only need to change the template.

 

This has the benefit of accepting any rule name (and more than one rule if necessary). On the other hand, you risk having user overwriting the part when their intention was to modify it and save as a new part.

0 Likes
Message 11 of 13

gcoombridge
Advisor
Advisor

@j.haggenjos  and @WCrihfield the template worked and thank you both for the in-depth information on the subject. 

 

 

Use iLogic Copy? Please consider voting for this long overdue idea (not mine):https://forums.autodesk.com/t5/inventor-ideas/string-replace-for-ilogic-design-copy/idi-p/3821399
0 Likes
Message 12 of 13

rdhillon6HET8
Contributor
Contributor

Hi there. Just came across this thread. Many thanks to @WCrihfield for providing those links. That was an awesome read. I am trying to run an external rule trigger on "part geometry change". I have a question for @WCrihfield. What did you mean by adding "file://" to the rule name. 

 

I want to test it but could not get it work because I did not quite understand what did you mean by that . Could you please elaborate ?

 

Many thanks. 

rdhillon6HET8_1-1674751182023.png

 

 

 

0 Likes
Message 13 of 13

WCrihfield
Mentor
Mentor

Hi @rdhillon6HET8.  I learned about this through manually adding an external rule to the Event Triggers dialog, under one of the events, then using some exploratory code to read the resulting 'property' name, and its value that was created within that hidden PropertySet as a result of that.  What I found is that when I manually add an external rule, it automatically adds the text "file://" to the start of the rule's name.  So, if the name of the external rule I added manually was "RunRule1", then the value of the new property that was created would be "file://RunRule1", instead of just "RunRule1".  With that in mind, since I was doing this entirely by code, I needed to add that "file://" text to the start of any external rule's name before adding that resulting name as the value of a new property that I create by code, to enable that external rule to get triggered to run when that event happens, because it was not being done automatically for me when doing it by code.  When doing it manually, there must be some sort of other code(s) that run in the background as a helper for this detail.

Wesley Crihfield

EESignature

(Not an Autodesk Employee)

0 Likes