NX Reading input from Tk Window and Writing out to NC Output File

2021-10-06T23:27:26Z
NX for Manufacturing

Summary


Details

Unable to find an example on how to create a Tk dialog box and proc necessary to open a file, capture the information input into the dialog box, and finally output the data into the NC output file.



Solution

Open the out-of-the-box sim_07_mill_5ax_fanuc_in.pui in Post Builder.
  • File-->Save As-->Tk_sim_07_mill_5ax_fanuc_in (save in desired location).
  • Go to the "Program Start Sequence".
  • Create a custom command and place it directly after the "%" (Please see image below).
  • The sample custom command is below...The proc is sourcing in custom_retrieve_input.tcl.
custom_retrieve_input.tcl  (found in the UGII_CAM_POST_DIR)
 (please see source code below)
##############################################################################
#
# This procedure executes a user input window and retrieves information
# for program number and a description. Execute this proc at the beginning
# of post processing and use the info in the variables where and how you like.
#_____________________________________________________________________________
proc  get_init_data {} {
  global fn
  global prog_num
  global description_prog
 
# Open the temp file and extract the information into variables
 
  set fn [open c:\\temp\\temp.dat w]
  set a [open "| {D:\\Siemens\\NX 1847\\MACH\\auxiliary\\ugwish.exe}  {D:\\Siemens\\home_nx1847\\resource\\postprocessor\\custom_entry_window.tcl} "    ]
  
gets $a line
 
   set fn [open c:\\temp\\temp.dat r ]
   gets $fn prog_num
   gets $fn description_prog
 
  close $fn 
# Now convert the description to upper case and save in a variable "description_prog"
 
  set description_prog [string toupper $description_prog]
}


  • Note: The script executes ugwish.exe and runs custom_entry_window.tcl.
custom_entry_window.tcl  (found in the UGII_CAM_POST_DIR)
 (please see source code below)


#"D:\Siemens\NX 1847\MACH\auxiliary\ugwish.exe"
wm title . "Program Information"
#
#
# Label for Program Number
#
font create courierfont -family Courier -size 12 -weight bold -slant italic 
label .prog_frame_label -text "  Program Information  " -font courierfont -relief sunken -background gray
.prog_frame_label configure
pack .prog_frame_label -pady 1m -fill x
#
# Create a frame to make things look nice for the Program Name
#
frame .prog_frame 
pack .prog_frame -anchor w
#
# Create a Label for the Program Name
# Pack this in the previous frame (.prog_frame)
#
label .prog_label -text "Program Number:"
.prog_label configure 
entry .prog_entry -width 4 -relief sunken -bd 2 -textvariable prog_num
pack .prog_label .prog_entry -side left -padx 1m -pady 1m -in .prog_frame
 
#
# Create a frame to make things look nice for the Description
#
frame .desc_frame 
pack .desc_frame -anchor w
#
# Create a Label for the Description_Prog
# Pack this in the previous frame (.desc_frame)
#
label .desc_label -text "Description:"
entry .desc_entry -width 20 -relief sunken -bd 2 -textvariable description_prog
pack .desc_label .desc_entry -side left -padx 1m -pady 1m -in .desc_frame
# Now for the OK button and write the info out to a text file
#  called temp.dat for retrieval by the "get_init_data" procedure
# -----------------------------------------------
#             OK Button
#------------------------------------------------
button .ok -text "Continue Post Processing" -command {
           set tempfile c:\\temp\\temp.dat
 global outfile
 global prog_num
 global description_prog
 
           set outfile [open $tempfile w]
           puts $outfile "$prog_num"
           puts $outfile "$description_prog"
           close $outfile
          destroy .
}
# Pack the OK button
pack .ok -side top -padx 2m -pady 1m -fill x
# And we're done
Note: A file is written out to C:\temp\temp.dat when the information is input into the Tk dialog box.

To output the code, another custom command will be added just below PB_CMD_gather_info_from_Tk_window, in Post Builder (please see image below).

  • Save the post and test in NX.
  • Open sim07_mill_5ax_cam_fanuc_in.prt.
  • Select "ROUGHING" Program group with MB3 --> select Post Process.
  • Select Tk_sim07_mill_5ax_fanuc_in and OK to post process.
Dialog boxes is presented to user...

  • Input 7899 into "Program Number".
  • Input sim07_tk_test into "Description".
Completed input seen in image below...



  • Select "Continue Postprocessing".
  • Please see sample output below. The 2nd line is the output from the Tk window.


%
O7899 (SIM07_TK_TEST)
N1 G40 G17 G90 G49 G20
N2 (FACE_TOP)
N3 G91 G28 Z0.0
N4 G91 G28 X0.0 Y0.0
N5 G90 G53 G00 B0.0 C0.0
:6 T1 M06

Hardware/Software Configuration

Platform: all
OS: n/a
OS Version: n/a
Product: NX
Application: CAM
Version: V1847
Function: POSTBUILDER

Ref: 002-8015258

KB Article ID# PL8015258

Contents

SummaryDetails

Associated Components

Manufacturing Post Builder