Cancel
Showing results for 
Search instead for 
Did you mean: 

Custom Tool List from Postbuilder

Genius
Genius

I'd like to add a command to all my posprocessors (and I have many of them) to output a tool list at the beginning of each posted program.

I tried several differenet suggestions from Newsgroups but am not happy with them.  

 

Here is what I'd like to do and need some TCL help:

 

I'd like to capture at each of my tool change  $mom_tool_number and $mom_tool_description into an array.

Then at the end of postprocessing I'd like to (if possible) sort this array by tool number while deleting any redundant tool numbers.

 

The next steps I know how to do but if there is easier way I'm all ears:

output array to a temp file

close main file

copy temp file to the beginning of the main file

delete temp file

 

Thanks all,

Jerry

NX10.0.1

 

4 REPLIES

Re: Custom Tool List from Postbuilder

Solution Partner Genius Solution Partner Genius
Solution Partner Genius

Hello,

 

you can do the following:

 

1. In the start of program:

 

if { [file exists "${path_post}/Tool_List.tcl"] } {
set exito [MOM_run_postprocess "${path_post}/Tool_List.tcl" "${path_post}/your_post.def" "Tool_List.info"]
set part_dir "[file dirname $::mom_part_name]/"
set name_file_toolist "${part_dir}Tool_List.info"
set fic_lista [open $name_file_toolist r ]
set bloque [gets $fic_lista]
set ii 1
foreach {a1 a2} $bloque {
set tool_name($ii) $a1
set tool_description($ii) $a2
set ii [expr $ii + 1]
}
while {[eof $fic_lista] == 0} {
set bloque [gets $fic_lista]
foreach {a1 a2 } $bloque {
set tool_name($ii) $a1
set tool_description($ii) $a2
set ii [expr $ii + 1]
}
}

close $fic_lista

}

 

Now you have the info of you like.

 

You will need create a file.tcl for write the values for each line of tool_name and tool_description in the file.info

 

Finally you could delete the file: file delete -force $file_info

 

I recommend you writing these questions in the postprocessors forum: https://community.plm.automation.siemens.com/t5/NX-CAM-Postprocessor-Group/gp-p/NX-CAM-Postprocessor...

 

Best regards,

 

 

 

 

Re: Custom Tool List from Postbuilder

Legend
Legend

There is an simple way for doing this.

You can use the "pb_cmd_tool_list.tcl" File which is stored in 

"...NXxx\POSTBUILD\pblib\custom_command\"

 

Regards

Re: Custom Tool List from Postbuilder

Valued Contributor
Valued Contributor

As an alternative @schauerm3's method, but not as convenient as his suggestion, you can use another approach:

 

  • Put a tool list place holder output in the start of program
  • Add current tool to tool_list variable in tool change event
  • If current tool is unique, add your extra information to tool_list_detailed
  • Replace tool_list place holder with tool_list_detailed at the end of posting

 

You can create a list type variable in tcl to hold tool names, if current tool is in that list, obviously it will not be unique.

	if {[info exists mom_tool_name] && [info exists mom_tool_number] && [lsearch -exact $tool_list_name $mom_tool_name] } {

If this condition matches then you can add current tool with extra information (to another string or list). If you choose to sort your tool list, you can do it with a list type variable.

 

Replace place holder using something like this:

	if { [info exists mom_output_file_full_name] } {
		MOM_close_output_file $mom_output_file_full_name
		set timestamp [clock format [clock seconds] -format {%Y%m%d%H%M%S}]

		set filename $mom_output_file_full_name
		set temp     $filename.new.$timestamp
		set backup   $filename.bak.$timestamp
	
		set in  [open $filename r]
		set out [open $temp     w]

		# line-by-line, read the original file
		while {[gets $in line] != -1} {
			#placeholder to tool list
			if { [string match "*TOOLLISTPLACEHOLDER*" $line] } { foreach item $tool_list_number_and_name { puts $out $item }; set line ""} 
			puts $out $line
		}

		close $in; close $out

		# move the new data to the proper filename
		#file link -hard $filename $backup
		file rename -force $temp $filename 
	}

 

Like I said, it is not easy as mentioned method, you have to do testing, many coding etc. This methods becomes complicated when you need sorting. Kind of information that is available to some tools but not others (Pitch value for taps?) makes it also complicated to maintain code.

 

 

Re: Custom Tool List from Postbuilder

Siemens Legend Siemens Legend
Siemens Legend

If you have many posts that you want to produce a tool list, I would source the code, rather then putting it into every post. 

Learn online





Solution Information