Showing results for 
Search instead for 
Do you mean 
Reply

moog_show_​globals - reposted

Here's the code (indenting may be a bit suspect):

#=================================================​============
proc MOOG_Show_Globals { } {
#=================================================​============
# Shows all globals -
# including arrays, and their values
# Just put call to this proc wherever you need it
# You probably want to add some code around the call 
# so you only output data one (or a few) times
#
# Warning - if added as a custom commend, it takes a while for Postbuilder
# to check this proc (i.e. Do not click on it to look at the code)
#
# KG Akerboom 15-Nov-2005
#
#

set global_vars [lsort [info globals]]

MOM_output_to_listing_device "-----------------Global Vars-------------------"
foreach global_var $global_vars {
 # Comment out these next lines if you actually want to see this info
 #if [string compare $global_var "errorInfo"] {} else {continue}
 #if [string compare $global_var "env"] {} else {continue}
 #if [string compare $global_var "tcl_platform"] {} else {continue}
 #if {[string first "mom_tool_use" $global_var] >= 0} {continue}
 #if {[string first "mom_tool" $global_var] >= 0} {continue}
 #if {[string first "mom_display" $global_var] >= 0} {continue}
 #if {[string first "mom_feed" $global_var] >= 0} {continue}
 #if {[string first "mom_kin" $global_var] >= 0} {continue}
 #if {[string first "mom_sys" $global_var] >= 0} {continue}

 # if {[string first "pos" $global_var] < 0} {continue}
 
 upvar #0 $global_var global_val
  if [catch {set glob_value $global_val}] {
   foreach el [lsort [array names global_val]] {
    # so it doesn't try to substitute value of element of array in left hand side
    set el2 "($el)"
    MOM_output_to_listing_device "$global_var$el2 = $global_val($el)"
   }
  } else {
   MOM_output_to_listing_device "$global_var = $glob_value"
  }
 } 

MOM_output_to_listing_device "------------------------------------------------"
}

 

Ken Akerboom Sr CAx Systems Engr, Moog, Inc.
Production: NX10.0.3.5 MP5 + patch/TC11.2
I'd rather be e-steemed than e-diseaseled


2 REPLIES

Re: moog_show_​globals - reposted

Some notes on using it.

I just have it in an external .tcl file that I "source" into all my posts, then have a simple PB_CMD_* to call this external routine. The other option is to directly put the code (without "proc MOOG_Show_Globals { } {" and the trailing "}" ) into a PB_CMD.

1) It produces a LOT of output (200+ lines PER CALL). So use some discretion on where you put it.
If you want it on something like a "linear move" event, add some code to limit the number of times it is called:

Limit to one call:

global moog_debug_out
if {![info exists moog_debug_out]} {
 MOOG_Show_Globals
 set moog_debug_out 1
}

 limit to 5 calls:

global moog_debug_out
if {![info exists moog_debug_out]} {
 set moog_debug_out 0
}
if {$moog_debug_out < 5} {
 MOOG_Show_Globals
 incr moog_debug_out
}

 2) I also use mom_operation_name to only output on certain operations (or mom_tool_name for tools):

 

global mom_operation_name
global moog_debug_out
if {$mom_operation_name == "OPERATION_TO_TEST"} { <-- edited this line
 MOOG_Show_Globals
}

 or once per operation:

if {![info exists moog_debug_out($mom_operation_name) ]} {
 MOOG_Show_Globals
 set moog_debug_out($mom_operation_name) 1
}

 If I want to see how variables change between a lot of operations, I generlly use it on ONE operation to identify likely variables, then "mom_output_to_listing_device" just that short list of variables for every operation.

3) You can un-comment some of the "if {[string...} " lines to filter out SOME of the "clutter"

4) Another way I use it is to run it against one operation, then save the text from the "Information" window to a file. The run it against another operation (or change a parameter in the original op), and save that "info" window text to another file. Then use a text comparison utility (e.g. WinMerge) to compare the txt files to see what changed.

5) If you still can't figure out what variable is the one you want, try setting it to a "unique" value (e.g. "1.23456")
Then search for that value LEAVING OFF THE FINAL DIGIT in the info window (in this case, search for "1.2345", as the value may be "1.23459999999997" rather than "1.2345600000") (see the post about why "EQ_is_equal" exists)

Ken

 

Ken Akerboom Sr CAx Systems Engr, Moog, Inc.
Production: NX10.0.3.5 MP5 + patch/TC11.2
I'd rather be e-steemed than e-diseaseled


Re: moog_show_​globals - reposted

And at some point I need to test if "array exists" or "array size" can be used to test if a variable is an array (rather than assuming it is and "catching" the error if it isn't)

Ken Akerboom Sr CAx Systems Engr, Moog, Inc.
Production: NX10.0.3.5 MP5 + patch/TC11.2
I'd rather be e-steemed than e-diseaseled


Learn online





Solution Information