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: 

Getting Event Type Within Handler

2 REPLIES 2
SOLVED
Reply
Message 1 of 3
meGVGMF
218 Views, 2 Replies

Getting Event Type Within Handler

meGVGMF
Advocate
Advocate

Hi,

 

I was wondering if there was any way to get information about the event from within the handler assigned to it.

 

I have the same handler running on different triggers, each requiring a slightly different execution depending on the event type.

 

I know I can wrap this in a dedicated handler and parameterize a call to the rule from within this, but is there otherwise no way to get information about the event itself?

 

Thanks

0 Likes

Getting Event Type Within Handler

Hi,

 

I was wondering if there was any way to get information about the event from within the handler assigned to it.

 

I have the same handler running on different triggers, each requiring a slightly different execution depending on the event type.

 

I know I can wrap this in a dedicated handler and parameterize a call to the rule from within this, but is there otherwise no way to get information about the event itself?

 

Thanks

2 REPLIES 2
Message 2 of 3
Michael.Navara
in reply to: meGVGMF

Michael.Navara
Advisor
Advisor
Accepted solution

I strongly recommend you to use separate rule for each event handler. In the background you can call one external rule with specific arguments.

 

But to your question. It is possible but it can be little bit obscure and behavior can change in future without any information because it is not part of public iLogic API.

This code snippet show how to access underlying .NET call stack and print the called methods to the iLogic log. You need to analyze this callstack and determine which event runs this rule

 

 

Imports System.Diagnostics

'Get Call stack
Dim stackTrace As New StackTrace() 	

' Get method calls (frames)
Dim stackFrames As StackFrame() = stackTrace.GetFrames() 	

For Each stackFrame As StackFrame In stackFrames
	'Write method name
	Logger.Debug(StackFrame.GetMethod().Name)				
Next

 

 

My results for 

Part Geometry Changed eventBefore Save Document event
INFO| 19: >>---------------------------
DEBUG|Main
DEBUG|ExecRuleInAssembly
DEBUG|ExecRuleEval
DEBUG|EvalRule
DEBUG|EvalRule
DEBUG|RuleRun
DEBUG|VisitRule
DEBUG|RunListOfRules
DEBUG|RunInternalRules
DEBUG|OnSurfaceBodyChanged
DEBUG|InvokeMethod
DEBUG|UnsafeInvokeInternal
DEBUG|Invoke
INFO| 20: >>---------------------------
DEBUG|Main
DEBUG|ExecRuleInAssembly
DEBUG|ExecRuleEval
DEBUG|EvalRule
DEBUG|EvalRule
DEBUG|RuleRun
DEBUG|VisitRule
DEBUG|RunListOfRules
DEBUG|RunInternalRules
DEBUG|mobjApplicationEvents_OnSaveDocument
DEBUG|InvokeMethod
DEBUG|UnsafeInvokeInternal
DEBUG|Invoke

 

I strongly recommend you to use separate rule for each event handler. In the background you can call one external rule with specific arguments.

 

But to your question. It is possible but it can be little bit obscure and behavior can change in future without any information because it is not part of public iLogic API.

This code snippet show how to access underlying .NET call stack and print the called methods to the iLogic log. You need to analyze this callstack and determine which event runs this rule

 

 

Imports System.Diagnostics

'Get Call stack
Dim stackTrace As New StackTrace() 	

' Get method calls (frames)
Dim stackFrames As StackFrame() = stackTrace.GetFrames() 	

For Each stackFrame As StackFrame In stackFrames
	'Write method name
	Logger.Debug(StackFrame.GetMethod().Name)				
Next

 

 

My results for 

Part Geometry Changed eventBefore Save Document event
INFO| 19: >>---------------------------
DEBUG|Main
DEBUG|ExecRuleInAssembly
DEBUG|ExecRuleEval
DEBUG|EvalRule
DEBUG|EvalRule
DEBUG|RuleRun
DEBUG|VisitRule
DEBUG|RunListOfRules
DEBUG|RunInternalRules
DEBUG|OnSurfaceBodyChanged
DEBUG|InvokeMethod
DEBUG|UnsafeInvokeInternal
DEBUG|Invoke
INFO| 20: >>---------------------------
DEBUG|Main
DEBUG|ExecRuleInAssembly
DEBUG|ExecRuleEval
DEBUG|EvalRule
DEBUG|EvalRule
DEBUG|RuleRun
DEBUG|VisitRule
DEBUG|RunListOfRules
DEBUG|RunInternalRules
DEBUG|mobjApplicationEvents_OnSaveDocument
DEBUG|InvokeMethod
DEBUG|UnsafeInvokeInternal
DEBUG|Invoke

 

Message 3 of 3
meGVGMF
in reply to: Michael.Navara

meGVGMF
Advocate
Advocate

But the problem is, if I try to programmatically remove a rule, I have to remove either the generic handler or create unique handlers to remove, for each rule in which I need to know the event type.

0 Likes

But the problem is, if I try to programmatically remove a rule, I have to remove either the generic handler or create unique handlers to remove, for each rule in which I need to know the event type.

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

Post to forums  

Autodesk Design & Make Report