Ilogic to add ilogic to event triggers

Ilogic to add ilogic to event triggers

Charlies_3D_T
Advocate Advocate
1,546 Views
11 Replies
Message 1 of 12

Ilogic to add ilogic to event triggers

Charlies_3D_T
Advocate
Advocate

Hello,

 

Does someon know if it's possible to add a ilogic rule to event triggers? 

 

I want to run an ilogic rule and when it's finished i want it to be added to event triger at part geometry change.

 

Thank you!

0 Likes
Accepted solutions (1)
1,547 Views
11 Replies
Replies (11)
Message 2 of 12

HermJan.Otterman
Advisor
Advisor

search on inventor code injector

https://beinginventive.typepad.com/being-inventive/2012/02/injecting-ilogic-code-and-ilogic-event-tr...

If this answers your question then please select "Accept as Solution"
Kudo's are also appreciated Smiley Wink

Succes on your project, and have a nice day

Herm Jan


0 Likes
Message 3 of 12

Charlies_3D_T
Advocate
Advocate

Thank you but I Already use that one. But I want to write a rule that does that specificaly. 

0 Likes
Message 4 of 12

HermJan.Otterman
Advisor
Advisor

the injector code is open, you can debug it.

there are many comment lines explaning things.

in the code you will find some code to set the events, but it is not so simple

If this answers your question then please select "Accept as Solution"
Kudo's are also appreciated Smiley Wink

Succes on your project, and have a nice day

Herm Jan


0 Likes
Message 5 of 12

Sergio.D.Suárez
Mentor
Mentor
Accepted solution

Hi, here is an example I hope it is useful, it is a rule that after executing is automatically added to event, in the category of geometry change. For your rule in particular, replace the text box with your rule, or with the subroutine you have. Regards!!!

 

Sub main()
	
	
	
MessageBox.Show("Example", "Title")






Events
End Sub

Sub Events
On Error Resume Next
	Dim EventPropSet As Inventor.PropertySet
	EventPropSet = GetiLogicEventPropSet(ThisApplication.ActiveDocument)
	EventPropSet.Add("Inicio", "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()
	

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

 


Please accept as solution and give likes if applicable.

I am attaching my Upwork profile for specific queries.

Sergio Daniel Suarez
Mechanical Designer

| Upwork Profile | LinkedIn

Message 6 of 12

Charlies_3D_T
Advocate
Advocate

@Sergio.D.Suárez 

 

Thank you that was what i needed!!!

 

Message 7 of 12

Charlies_3D_T
Advocate
Advocate

@Sergio.D.Suárez

 

Do you know how to declare the same rule but for an external rule?

 

So i want to place an external rule in the event triggers now. But if i change the name to the name of the external one it's not working.  

Message 8 of 12

LarsBJepsen
Advocate
Advocate

Hi

 

@Charlies_3D_T  did you ever find a solution for declaring an external rule?

 

/Lars 

0 Likes
Message 9 of 12

Charlies_3D_T
Advocate
Advocate

@LarsBJepsen 

 

What do you want to do? 

 

For example if i want to use an external rule is use this command:

 

iLogicVb.RunExternalRule("FlatPattern")

 

But important for you is to set the settings inside inventor that it knows where you put your external rules. 

 

0 Likes
Message 10 of 12

LarsBJepsen
Advocate
Advocate

I'm trying to add and external rule to an event trigger as in the code previous in the tread. It looks like you had the same issue earlier?

 

/Lars

0 Likes
Message 11 of 12

Charlies_3D_T
Advocate
Advocate

This is the solution normaly:

 

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://FlatPattern", "PartBodyChanged", 1250)
	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

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 12 of 12

guido_overath
Enthusiast
Enthusiast

Hi Sergio,

 

thank you very much for that great code snippet. I'm new in VBA so how do I need to modify your snippet in case of I need to add multiple triggers? I think I need something like a loop to get this result (that is defined in my new Template).

Thank you for your support/tipps.

 

Br

 

Guido

 

guidooverath_2-1663755644338.png

 

0 Likes