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
Solved! Go to Solution.
Solved by FarrenYoung. Go to Solution.
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.
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?
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
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).