Cancel
Showing results for 
Search instead for 
Did you mean: 

Re: NX10 Incorporating "Notes" into either setup sheets or top of posts.

Phenom
Phenom

A quick note.

foreach i [lsort [array names mom_operation_notes]]

does not work for more than 10 lines

 

"lsort" is ascii sort by default and will sort 0-11 as:

 

 0 1 10 11 2 3 4 5 6 7 8 9

 

Better to use something like this

proc PB_CMD_output_notes { } {
	global mom_operation_notes
	global mom_sys_control_in
	global mom_sys_control_out
	
	set ci $mom_sys_control_in
	set co $mom_sys_control_out
	
	if {[info exists mom_operation_notes]} {
		for {set i 0} {$i<[array size mom_operation_notes]&&[info exists mom_operation_notes($i)]} {incr i} {
				MOM_output_literal "[format "%s%s%s" $co $mom_operation_notes($i) $ci]"
		}
		unset mom_operation_notes
	}
}

Re: NX10 Incorporating "Notes" into either setup sheets or top of posts.

Gears Esteemed Contributor Gears Esteemed Contributor
Gears Esteemed Contributor

Note that you can use

[lsort -integer [array names mom_operation_notes]]

 

Which should work correctly for any array size.

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


Re: NX10 Incorporating "Notes" into either setup sheets or top of posts.

PLM World Member Phenom PLM World Member Phenom
PLM World Member Phenom

Thanks for this proc!!

 

I have tried this and it works great.  The only strange thing is if I delete the contents of the note I get 1 blank line () output from the operation.

John Joyce, Manufacturing Engineer,
Senior Aerospace

NX 11.0.2.7 Vericut 8.0.3 - Statements and opinions are mine alone and do not reflect
the opinion of my employer or any other member of the human race

Re: NX10 Incorporating "Notes" into either setup sheets or top of posts.

Phenom
Phenom

Ken,

I had looked at that

It just looks a bit odd to sort something that already has an order :-)

 

Camster,

I have seen that before. Not sure if I found a solution.

Maybe string length 

I'll see if I can dig it up

Re: NX10 Incorporating "Notes" into either setup sheets or top of posts.

Gears Esteemed Contributor Gears Esteemed Contributor
Gears Esteemed Contributor

the "-integer" tells the lsort HOW to sort the array list

 

re: Blank line:

you might want to test if there is anything in the variable:

 

if {[string length $mom_operation_notes($i)]} {
     # then output here
}

 

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


Re: NX10 Incorporating "Notes" into either setup sheets or top of posts.

Phenom
Phenom

I get that lsort -integer sorts it in the right order.

Sorting something that is already ordered is inefficient.

Sorting is more overhead even if its less to type.

 

Anyway both work.

 

 

 

Re: NX10 Incorporating "Notes" into either setup sheets or top of posts.

Thanks everyone for their tips here. I do just enough tcl to be dangerous, so this is interesting.

Based on the various comment, and after talking to the developer, here is an updated custom command. This will skip blank lines, so if you really want a blank line, you need to put a space in the note editor.

 

#=============================================================
proc PB_CMD_output_operation_notes { } {
#=============================================================
#
#  Output operation notes one line at a time.
#  Add this to the Start of Path event. 
#
   global mom_operation_notes

  # If notes are defined, output each line of text from the array.
   if { [info exists mom_operation_notes] && [array exists mom_operation_notes] } {

      OPERATOR_MSG "------------------- Operation Notes ----------------------"
      foreach i [lsort -integer [array names mom_operation_notes]] {
         if [info exists mom_operation_notes($i)] {
         OPERATOR_MSG "$mom_operation_notes($i)"
         }
      }
		OPERATOR_MSG "----------------------------------------------------------"

     # Clear for next operation
      array unset mom_operation_notes
   }
}

 

Sample output:

%
N0010 G40 G17 G90 G71
( ------------------- Operation Notes ---------------------- )
( Test multiple line notes )
( Line 2 )
( Line 3 )
(   )
( Line 5 (4 was a space) )
( Line 6 )
( Line 7 )
( Line 8 )
( Line 9 )
( Line 10 )
( Line 11 the end )
( ---------------------------------------------------------- )
N0020 G91 G28 Z0.0
Mark Rief
Retired Siemens

Re: NX10 Incorporating "Notes" into either setup sheets or top of posts.

Phenom
Phenom

I should check my code before opening my mouth;

Running the following code in tclsh

 

% time {byindex1} 1000

7042 microseconds per iteration
% time {bysort} 1000
563 microseconds per iteration
% time {byindex2} 1000
343 microseconds per iteration

If [array size] is not called each iteration the loop by index is faster than "foreach lsort".

 

anyway tilting at windmills again :-)

 

 

global test

for {set i 0} {$i<1000} {incr i} {
	set test($i) [format "Line %d" $i]
}

proc byindex1 {} {
	global test
	for {set i 0} {$i<[array size test]} {incr i} {
		set tmp $test($i)
	}
}

proc byindex2 {} {
	global test
	set j [array size test]
	for {set i 0} {$i<$j} {incr i} {
		set tmp $test($i)
	}
}

proc bysort {} {
	global test
	foreach i [lsort -integer [array names test]] {
		set tmp $test($i)
	}
}

 

Re: NX10 Incorporating "Notes" into either setup sheets or top of posts.

Gears Esteemed Contributor Gears Esteemed Contributor
Gears Esteemed Contributor

Mark -

Must be my day to nit-pick.

Most Fanuc-like controls I have dealt with don't like embedded parentheses...The following line will probably error on the control:

 

( Line 5 (4 was a space) )

 

 

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


Re: NX10 Incorporating "Notes" into either setup sheets or top of posts.

Gears Esteemed Contributor Gears Esteemed Contributor
Gears Esteemed Contributor

agrivas -

Being curious - could you get the timing for:

 

proc bysort2 {} {
	global test
	set indices [lsort -integer [array names test]] 
	foreach i $indices {
		set tmp $test($i)
	}
}
Ken Akerboom Sr CAx Systems Engr, Moog, Inc.
Production: NX10.0.3.5 MP16/TC11.2
I'd rather be e-steamed than e-diseaseled


Learn online





Solution Information