cancel
Showing results for 
Search instead for 
Did you mean: 

Scope of procedures in post builder

Can someone explain the scope of procedures in post builder?

 

When you post a file are the procs just ran through the initial check phase of tcl, or does it execute the substitution step as well? I'm confused as to why sometimes they seem to be executed by themselves, sometimes you have to call them and why it tells me they are not defined in the current scope of my post, when I defined them in another custom command.

 

If I'm creating a procedure that doesn't have any arguments passed to it (everything I want to do is self contained in the proc) do I need to initialize it at the start of program event before being able to call it and have it run? Does the tcl file associated with your post get run when it gets sourced or is it just made available?

 

Last thing is I know that every window in post builder is a procedure, so does that change the scope I'm working in when creating and calling procedures defined in other places? Meaning do I need to uplevel everything so that it is visible from wherever I'm currently at in the scope of the post?

 

Sorry if that's massively confusing, I'm confused!

Jake Hardwick
CNC Programmer
Senior Aerospace AMT
Production NX8.5.3.3 Beta testing NX10.0.1.4
18 REPLIES

Re: Scope of procedures in post builder

Valued Contributor
Valued Contributor

I might be confused here. Smiley Happy But if you create a procedure under "custom command" you can call it where ever you want. 

 

If you have your procedures outside the postprocessor file, just source them early in the "program start sequence". Then your procedures are available. 

 

postprocessor procedure.png

W10 NX11.0.1

Re: Scope of procedures in post builder

That's what I thought, but then I realize you're calling a procedure from inside another procedure, and I don't understand what the scope of that is.  Also, when I run my post is the procedure defined? Or do I have to call it twice, once to establish it and once to execute it?

Capture.JPG

Jake Hardwick
CNC Programmer
Senior Aerospace AMT
Production NX8.5.3.3 Beta testing NX10.0.1.4

Re: Scope of procedures in post builder

Valued Contributor
Valued Contributor

Interesting, never had this problem. But the other command PB_CMD_AMT_MOOG does work. Where did you define it? I don't see it with the other custom commands. 

 

And, you could check the tcl file itself to see if, where and how the PB_CMD_AMT_alt_pos_def is defined. 

 

Or, maybe you are doing something inside PB_CMD_AMT_alt_pos_def which postbuilder doesn't like. If you emtpy the procedure or comment out all code in it, do you still have the same error?

W10 NX11.0.1

Re: Scope of procedures in post builder

This is what my PB_CMD_AMT_alt_pos_def (it's basically the swap dual head elements procedure that I tweaked)

 

#=============================================================
proc PB_CMD_AMT_alt_pos_def { } {
#=============================================================
uplevel #0 {

#=============================================================
proc PB_swap_pos_output { } {
#=============================================================
  global mom_output_file_directory mom_logname

   set def_file_name  "${mom_output_file_directory}__${mom_logname}_tmp_def_file_[clock clicks].def"
   if { [catch { set tmp_file [open "$def_file_name" w] } res] } {
      if { [llength [info commands PAUSE] ] } {
         PAUSE "Error in PB_CMD_AMT_alt_pos_def" $res
      }

      CATCH_WARNING $res
return
   }

   puts $tmp_file "MACHINE mill"
   puts $tmp_file ""
   puts $tmp_file "FORMATTING"
   puts $tmp_file "\{"
   puts $tmp_file "  ADDRESS fourth_axis"
   puts $tmp_file "  \{"
   puts $tmp_file "      FORMAT      Rotary"
   puts $tmp_file "      FORCE       off"
   puts $tmp_file "      MAX         999999.999 Truncate"
   puts $tmp_file "      MIN         -999999.999 Truncate"
   puts $tmp_file "      LEADER      \[\$mom_sys_leader(fourth_axis)\]"
   puts $tmp_file "      ZERO_FORMAT Zero_real"
   puts $tmp_file "  \}"
   puts $tmp_file ""
   puts $tmp_file "  ADDRESS fifth_axis"
   puts $tmp_file "  \{"
   puts $tmp_file "      FORMAT      Rotary"
   puts $tmp_file "      FORCE       off"
   puts $tmp_file "      MAX         999999.999 Truncate"
   puts $tmp_file "      MIN         -999999.999 Truncate"
   puts $tmp_file "      LEADER      \[\$mom_sys_leader(fifth_axis)\]"
   puts $tmp_file "      ZERO_FORMAT Zero_real"
   puts $tmp_file "  \}"
   puts $tmp_file ""
   puts $tmp_file "  BLOCK_TEMPLATE circular_move"
   puts $tmp_file "  \{"
   puts $tmp_file "      G_motion\[\$mom_sys_circle_code(\$mom_arc_direction)]\\opt"
   puts $tmp_file "      G_mode\[\$mom_sys_output_code(\$mom_output_mode)\]"
   puts $tmp_file "      G_cutcom\[\$mom_sys_cutcom_code(\$mom_cutcom_status)\]\\opt"
   puts $tmp_file "      G_feed\[\$mom_sys_feed_rate_mode_code(\$feed_mode)\]\\opt"
   puts $tmp_file "      X\[\$mom_pos(0)\]"
   puts $tmp_file "      Y\[\$mom_mcs_goto(1)\]"
   puts $tmp_file "      Z\[\$mom_mcs_goto(2)\]"
   puts $tmp_file "      I\[\$mom_pos_arc_center(0) - \$mom_prev_pos(0)\]"
   puts $tmp_file "      J\[\$mom_pos_arc_center(1) - \$mom_prev_pos(1)\]"
   puts $tmp_file "      K\[\$mom_pos_arc_center(2) - \$mom_prev_pos(2)\]"
   puts $tmp_file "      F\[\$feed\]"
   puts $tmp_file "  \}"
   puts $tmp_file ""
   puts $tmp_file "  BLOCK_TEMPLATE rapid_move_3"
   puts $tmp_file "  \{"
   puts $tmp_file "      X_init_rapid_pos\[\$X_init_pos\]"
   puts $tmp_file "      Y_init_rapid_pos\[\$Y_init_pos\]"
   puts $tmp_file "      fifth_axis\[\$mom_out_angle_pos(1)\]"
   puts $tmp_file "      fourth_axis\[\$mom_out_angle_pos(0)\]"
   puts $tmp_file "  \}"
   puts $tmp_file ""
   puts $tmp_file "  BLOCK_TEMPLATE safety_line_3"
   puts $tmp_file "  \{"
   puts $tmp_file "      G\[\$mom_sys_return_code\]"
   puts $tmp_file "      Y\[\$mom_sys_home_pos(1)\]"
   puts $tmp_file "      fifth_axis\[0.0\]"
   puts $tmp_file "      fourth_axis\[0.0\]"
   puts $tmp_file "  \}"
   puts $tmp_file ""
   puts $tmp_file "  BLOCK_TEMPLATE linear_move"
   puts $tmp_file "  \{"
   puts $tmp_file "      G_motion\[\$mom_sys_linear_code\]"
   puts $tmp_file "      G_mode\[\$mom_sys_output_code(\$mom_output_mode)\]"
   puts $tmp_file "      G_plane\[\$mom_sys_cutcom_plane_code(\$mom_cutcom_plane)\]\\opt"
   puts $tmp_file "      G_cutcom\[\$mom_sys_cutcom_code(\$mom_cutcom_status)\]\\opt"
   puts $tmp_file "      D\[\$mom_cutcom_adjust_register\]\\opt"
   puts $tmp_file "      G_feed\[\$mom_sys_feed_rate_mode_code(\$feed_mode)\]\\opt"
   puts $tmp_file "      X\[\$mom_pos(0)\]"
   puts $tmp_file "      Y\[\$mom_mcs_goto(1)\]"
   puts $tmp_file "      Z\[\$mom_mcs_goto(2)\]"
   puts $tmp_file "      fifth_axis\[\$mom_out_angle_pos(1)\]"
   puts $tmp_file "      fourth_axis\[\$mom_out_angle_pos(0)\]"
   puts $tmp_file "      F\[\$feed\]"
   puts $tmp_file "  \}"
   puts $tmp_file ""
   puts $tmp_file "  BLOCK_TEMPLATE rapid_spindle"
   puts $tmp_file "  \{"
   puts $tmp_file "      G_motion\[\$mom_sys_rapid_code\]"
   puts $tmp_file "      G_mode\[\$mom_sys_output_code(\$mom_output_mode)\]\\opt"
   puts $tmp_file "      G_adjust\[\$mom_sys_adjust_code\]"
   puts $tmp_file "      H\[\$mom_tool_adjust_register\]\\opt"
   puts $tmp_file "      X\[\$mom_pos(0)\]"
   puts $tmp_file "      Y\[\$mom_mcs_goto(1)\]"
   puts $tmp_file "      Z\[\$mom_mcs_goto(2)\]"
   puts $tmp_file "      fifth_axis\[\$mom_out_angle_pos(1)\]"
   puts $tmp_file "      fourth_axis\[\$mom_out_angle_pos(0)\]"
   puts $tmp_file "  \}"
   puts $tmp_file ""
   puts $tmp_file "  BLOCK_TEMPLATE rapid_traverse"
   puts $tmp_file "  \{"
   puts $tmp_file "      G_motion\[\$mom_sys_rapid_code\]"
   puts $tmp_file "      G_adjust\[\$mom_sys_adjust_code\]"
   puts $tmp_file "      H\[\$mom_tool_adjust_register\]\\opt"
   puts $tmp_file "      G_feed\[\$mom_sys_feed_rate_mode_code(IPM)\]"
   puts $tmp_file "      X\[\$mom_pos(0)\]"
   puts $tmp_file "      Y\[\$mom_mcs_goto(1)\]"
   puts $tmp_file "      Z\[\$mom_mcs_goto(2)\]"
   puts $tmp_file "      fifth_axis\[\$mom_out_angle_pos(1)\]"
   puts $tmp_file "      fourth_axis\[\$mom_out_angle_pos(0)\]"
   puts $tmp_file "  \}"
   puts $tmp_file ""
   puts $tmp_file "  BLOCK_TEMPLATE first_tool_3"
   puts $tmp_file "  \{"
   puts $tmp_file "      G_mode\[\$mom_sys_output_code(ABSOLUTE)\]"
   puts $tmp_file "      G10\[10\]"
   puts $tmp_file "      L20\[20\]"
   puts $tmp_file "      order\[\$mom_fixture_offset_value\]"
   puts $tmp_file "      X\[\$mom_sys_home_pos(0)\]"
   puts $tmp_file "      Y\[\$mom_sys_home_pos(1)\]"
   puts $tmp_file "      Z\[\$mom_sys_home_pos(2)\]"
   puts $tmp_file "      fifth_axis\[\$mom_out_angle_pos(1)\]"
   puts $tmp_file "      fourth_axis\[\$mom_out_angle_pos(0)\]"
   puts $tmp_file "  \}"
   puts $tmp_file ""
   puts $tmp_file "\}"

   close $tmp_file

   MOM_load_definition_file  $def_file_name
   MOM_remove_file           $def_file_name
}

}
}

 

The MOOG_show_globals is there, I just wasn't scrolled up far enough.

Jake Hardwick
CNC Programmer
Senior Aerospace AMT
Production NX8.5.3.3 Beta testing NX10.0.1.4

Re: Scope of procedures in post builder

Valued Contributor
Valued Contributor

Well, I put your code in my post but I don't see any problem. Your codeblock is straight from the tcl file I hope? So in postbuilder it starts like this: 

uplevel #0 {

#=============================================================
proc PB_swap_pos_output { } {
#=============================================================
  global mom_output_file_directory mom_logname

 and not like this?

#=============================================================
proc PB_CMD_AMT_alt_pos_def { } {
#=============================================================
uplevel #0 {

#=============================================================
proc PB_swap_pos_output { } {
#=============================================================
  global mom_output_file_directory mom_logname

 

About the scope, all procs under "custom command" are on the same level. If PB_CMD_AMT_MOOG_show_globals works than any procedure should work.

 

The only suggestion I have left is to start simple. So, empty  PB_CMD_AMT_alt_pos_def, only uplevel a simple procedure which outputs some text and see if it works. 

W10 NX11.0.1

Re: Scope of procedures in post builder

Yes, I just copied the tcl file for the procedure.  I just wanted to show that I was defining a procedure in a custom command, trying to run the custom command at the begining of my program to define the procedure and then if my conditional stament later in the program was true it would run the procedure and change my definition file.  It still doesn't work even if I change the procedure to "return 1" and try to save my post.

Jake Hardwick
CNC Programmer
Senior Aerospace AMT
Production NX8.5.3.3 Beta testing NX10.0.1.4

Re: Scope of procedures in post builder

Esteemed Contributor
Esteemed Contributor

This is one reason I define all my procs in a separate tcl file and "source" it in.

I've found over the years that (often enough to be annoying) the "checking" done in PB_CMD_* procs complains about things that aren't really problems.

 

One question for you:

Did you try to add both procs in the same PB session?

Maybe try adding the one you are calling, save/close/re-open the post, then adding the one where it is called.  When you open a post in PB it seems to "register" custom commands.  Which might help in your case.

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: Scope of procedures in post builder

That seems to be it Ken.  If you make a procedure and then reference it before saving your post it doesn't know that it's there yet.  If you make a procedure and then re-open it and give it a chance to look at your new tcl file then it doesn't complain.  

 

Do you have ALL your custom procedures defined in a seperate file and source them all in?

Jake Hardwick
CNC Programmer
Senior Aerospace AMT
Production NX8.5.3.3 Beta testing NX10.0.1.4

Re: Scope of procedures in post builder

Esteemed Contributor
Esteemed Contributor

Pretty much all of my procs are in a separate file. Typically (looking in the TCL file created by PB) I'll have something like:

 

proc PB_CMD_Moog_XXX_XXXX_XXXX { } {
    # Comments on where to put PB_CMD
 
    # now call external proc
    Moog_XXX_XXXX_XXXX 

}

 

Then have Moog_XXX_XXXX_XXXXX in the "source"d file.

Makes it REALLY easy to share code between posts .  For instance, I don't use the Siemens supplied Shop docs for my docs.  I have my own code.  But that code is writen ONCE, in ONE tcl file - that 60 (or 80 or whatever) posts share.

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