Inventor Engineer-To-Order (Read-Only)
Welcome to Autodesk’s Inventor ETO Forums. Share your knowledge, ask questions, and explore popular Inventor ETO topics.
cancel
Showing results for 
Show  only  | Search instead for 
Did you mean: 

Using reflection in ETO

6 REPLIES 6
SOLVED
Reply
Message 1 of 7
MarkBrouwersIntent
748 Views, 6 Replies

Using reflection in ETO

Hi,

Is there a way to retrieve the current rule/method name and designname. I want to use this for debugging purposes.

Something like 

Rule Frame_Ext As Frame 
	Dim temp As Frame

'Pseudo-code if debug? then printvalue(This.current_Designname+"/"+This.Current_RuleName) temp=localframe Return temp End Rule

 Where debug? is a global parameter that I can use to switch on/off the writing to the intent log file.

Hopes it makes sense what I'm asking.

 

Cheers,

Mark

6 REPLIES 6
Message 2 of 7

You can access the current design via the Me rule.  With this you could do

Me.designName

 to get the current design name.

I don't know of a built-in way to get the current rule, but I put together a work-around to get it.  If this is something that you plan to call a lot (10,000+ times) it might slow things down since it's forcing an exception to be thrown to get the rule name.

	' This method will return the name of the rule that called it
	' I just threw it together quickly and have not tested it thorougly so it may break in some cases
	Method GetCallingRuleName() As String
		Dim callingRuleName As String
		Try
			ref(Me, :SomeRuleNameThatWillNotExistJustToForceAnExceptionThrown)
		Catch Error
			Dim stackLength As Integer = err.ErrorDetail.EvaluationStack.length
			If stackLength > 0 Then
				callingRuleName = err.ErrorDetail.EvaluationStack.GetValue(1).RuleName
			Else
				callingRuleName = "N/A"
			End If
		End Try
		Return callingRuleName
	End Method

 I tested this by putting the method in the root design so it is accessible by any rules and it appears to work fine.

 

Below are the few rules I wrote to test this method along with the results.  I simulated rules tha call other rules to show a "deep" call stack to make sure the method still returns the right values.

Uncached Rule Test3_Rule As String
	Return Test2_Rule
End Rule

Uncached Rule Test2_Rule As String
	Return Test1_Rule
End Rule

Uncached Rule Test1_Rule As String
	Return GetCallingRuleName()
End Rule

 Intent >Test1_Rule
--> "Test1_Rule"
Intent >Test2_Rule
--> "Test2_Rule"
Intent >Test3_Rule
--> "Test3_Rule"
Intent >GetCallingRuleName()
--> "GetCallingRuleName"
Intent >


I hope this helps you!

Perhaps someone from Autodesk can let us know if there is a better way to know the current executing rule name.

--Farren

************************************************************************************
If this post helps, please click the "thumbs up" to give kudos
If this post answers your question, please click "Accept as Solution"
************************************************************************************
Message 3 of 7
JackGregory
in reply to: FarrenYoung

This is an interesting question.  Some caveats: because of mixins and inheritance, me.DesignName may not give you the name of the design the "current executing rule" was defined in.  Even worse, the notion of "current executing rule" is a little ambiguous, since there are likely to be dozens of rules currently executing.  But I think I understand what you want, and it is mostly possible for "normal" rules.

 

But the modern way to deal with this is to put a breakpoint in the debugger.  Is there some reason you can't do this?

Message 4 of 7

Hi Jack,

The reason I want to do this lays in the fact my application exists out of C# code and ETO rules. When I'm debugging my c# code in Visual Studio, I can't use the _Debug-statement or use breakpoints in ETO. Unless I'm wrong and it's possible to debug simultaneous in both environments ?

 

Cheers,

Mark

Message 5 of 7

Did my suggestion work for you?
--Farren

************************************************************************************
If this post helps, please click the "thumbs up" to give kudos
If this post answers your question, please click "Accept as Solution"
************************************************************************************
Message 6 of 7

That is an excellent answer.  We cannot in fact do simulaneous debugging with C# and Intent.  I have also looked into how hard it would be to create some Intent language access to some of the content that we collect during exceptions, and this is definitely feasible, and I created a wish list entry for it (our id US1540).

Message 7 of 7

Sorry Farren,

Yes, your suggestion does work for me.

 

Cheers,

Mark

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

Post to forums  

Autodesk Design & Make Report