Adding external rule to event trigger

Adding external rule to event trigger

Charlies_3D_T
Advocate Advocate
3,752 Views
35 Replies
Message 1 of 36

Adding external rule to event trigger

Charlies_3D_T
Advocate
Advocate

Hello,

 

Does someone know how to declare an external rule to be added to event triggers?

 

Below is a piece of the ilogic for a local ilogic rule.

 

EventPropSet.Add("RULE TO Trigger", "PartBodyChanged ", 1200)

 

This doesn't work with external rules... 

 

Sub Events
On Error Resume Next
	Dim EventPropSet As Inventor.PropertySet
	EventPropSet = GetiLogicEventPropSet(ThisApplication.ActiveDocument)
	EventPropSet.Add("RULE TO Trigger", "PartBodyChanged ", 1200)

'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()

 

Thank you!

 

0 Likes
Accepted solutions (1)
3,753 Views
35 Replies
Replies (35)
Message 2 of 36

MjDeck
Autodesk
Autodesk

External rules are identified by the adding "file://" in front of the rule name. Here's a sample:

Sub Main()	
	Dim EventPropSet As Inventor.PropertySet
	EventPropSet = GetiLogicEventPropSet(ThisApplication.ActiveDocument)
	
	Call ListiProps(EventPropSet)
	
	' To make sure that the document has an iLogic DocumentInterest, add a temporary rule
	Dim tempRule = iLogicVb.Automation.AddRule(ThisDoc.Document, "TemporaryRule_392856A2", "")
	
	EventPropSet.Add("file://SampleExternalRule", "BeforeDocSave0", 700)
	iLogicVb.Automation.DeleteRule(ThisDoc.Document, tempRule.Name)
	
	Call ListiProps(EventPropSet)
End Sub

The temporary rule trick is required for documents that have no rules or event triggers.

Note: it's not a good idea to use absolute file paths for external rules. It's better to either put them in your project workspace, or set up a separate directory (using the iLogic Configuration command, which is on a dropdown under Tools > Options).

 

In Inventor 2018.1 and later, you can set event triggers to run external rules on all documents. This is often better than adding event triggers to each individual document.

 


Mike Deck
Software Developer
Autodesk, Inc.

Message 3 of 36

Charlies_3D_T
Advocate
Advocate

@MjDeck 

 

hello,

 

Thank you for your help. But for the moment i don't get it to work. And i can't figuring out why. 

 

My external rules are in one directory and i can access them from each part or drawing. But i can't get the rule to be placed in the event triggers. 

 

Sub Events
On Error Resume Next
	Dim EventPropSet As Inventor.PropertySet
	EventPropSet = GetiLogicEventPropSet(ThisApplication.ActiveDocument)
		
	' To make sure that the document has an iLogic DocumentInterest, add a temporary rule
	Dim tempRule = iLogicVb.Automation.AddRule(ThisDoc.Document, "TemporaryRule_392856A2", "")
	EventPropSet.Add("file://Drawing - Auto_AUTOCAD_DWG", "BeforeDocSave0", 700)
	iLogicVb.Automation.DeleteRule(ThisDoc.Document, tempRule.Name)
	

'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

iLogicVb.UpdateWhenDone = True
InventorVb.DocumentUpdate()


End Sub

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
0 Likes
Message 4 of 36

MjDeck
Autodesk
Autodesk

@Charlies_3D_T , are you using Inventor 2018.1 or later?


Mike Deck
Software Developer
Autodesk, Inc.

0 Likes
Message 5 of 36

Charlies_3D_T
Advocate
Advocate

@MjDeck 

 

Yes i have 2019.3 at the moment... 

0 Likes
Message 6 of 36

MjDeck
Autodesk
Autodesk

In 2019, you can set an external rule to run on all drawings. That's an alternative to adding a trigger to individual drawing documents.
Does that meet your requirements?


Mike Deck
Software Developer
Autodesk, Inc.

0 Likes
Message 7 of 36

Charlies_3D_T
Advocate
Advocate

@MjDeck 

 

No it doesn't. I really need to activate a rule after that all my drawings are made and then i need to activate it and past it in the event triggers so that when i make a change to a drawing it uses the rule again. 

 

Thanks for your fast response. 

0 Likes
Message 8 of 36

MjDeck
Autodesk
Autodesk

What does the rule do?


Mike Deck
Software Developer
Autodesk, Inc.

0 Likes
Message 9 of 36

Charlies_3D_T
Advocate
Advocate

@MjDeck 

 

it's just a simple AUTOCAD DWG export. 

 

But with specific naming. 

 

0 Likes
Message 10 of 36

MjDeck
Autodesk
Autodesk

And you want it to run for all drawings?


Mike Deck
Software Developer
Autodesk, Inc.

0 Likes
Message 11 of 36

Charlies_3D_T
Advocate
Advocate

Yes thats also a question i asked on the forum. And someon from autodesk fixed that for me. But now i want to add the external rule to the triggers. But i want to use the add for external rules for other rules i use also. 

0 Likes
Message 12 of 36

MjDeck
Autodesk
Autodesk

If you want it to run for all drawings, why not add it on the Drawings tab in the Event Triggers dialog? Then you don't need to add it to each document.


Mike Deck
Software Developer
Autodesk, Inc.

Message 13 of 36

Charlies_3D_T
Advocate
Advocate

@MjDeck 

 

For the AUTOCAD it's an option. But i also have a flatpattern rule and that has to be activated en added to the event triggers in specific parts. So i would need to fix this issue that i have now. 

 

0 Likes
Message 14 of 36

MjDeck
Autodesk
Autodesk

Do you have a rule or program that can find the parts that should have the flat pattern event trigger added to them?


Mike Deck
Software Developer
Autodesk, Inc.

0 Likes
Message 15 of 36

Charlies_3D_T
Advocate
Advocate

@MjDeck 

 

No i do the flatpattern manual so i open the part activate the rule and at the same time i has to be placed in the event trigger so that when i change something to the part it does the rule again.

 

 

0 Likes
Message 16 of 36

MjDeck
Autodesk
Autodesk

Ok, so you just want to automate the process of adding an event trigger to a single document?
You will decide you want to run a rule in that document.
Then you run it.
Then you run a separate rule to add an event trigger to run it automatically.


Mike Deck
Software Developer
Autodesk, Inc.

0 Likes
Message 17 of 36

Charlies_3D_T
Advocate
Advocate

@MjDeck 

 

Yes or I add the place rule to trigger in the rule I run. And This works with a local rule but the external rule is not place in the trigger and i don't know why. 

0 Likes
Message 18 of 36

MjDeck
Autodesk
Autodesk

The problem with putting it in the same rule is that it has to check if the trigger already exists before adding it again. You don't want the rule to run twice (or more) every time the event happens. 
That makes the code more complicated.

A related question: is your External Rules directory set up in the Tools > Options > iLogic Configuration dialog?


Mike Deck
Software Developer
Autodesk, Inc.

0 Likes
Message 19 of 36

Charlies_3D_T
Advocate
Advocate

@MjDeck

 

YEs it is. I have 2 sub directories one for drawings and one for parts and ass. 

 

SO if you say it's beter to use an second rule to place it in event triggers then I make a second one that is called when I run for example the flatpattern rule. And in the second rule can we add a check if it Already is in the event triggers? A'd if it is do not hing and otherwise place ut in the event trigger?

 

Is This something you can help me with? 

0 Likes
Message 20 of 36

MjDeck
Autodesk
Autodesk

Yes, I think I can help.
iLogic won't search for external rules in subdirectories. Since you have drawing rules in a subdirectory, please include the subdirectory name in this line of code:

EventPropSet.Add("file://Drawing - Auto_AUTOCAD_DWG", "BeforeDocSave0", 700)

Change it to something like this:

EventPropSet.Add("file://Drawing Rules\Drawing - Auto_AUTOCAD_DWG", "BeforeDocSave0", 700)

Mike Deck
Software Developer
Autodesk, Inc.

0 Likes