Cancel
Showing results for 
Search instead for 
Did you mean: 

If-else statement - post Builder

Solution Partner Genius Solution Partner Genius
Solution Partner Genius

Dear all,

 

I'm trying to edit a.pui file in postbuilder. This file gives an HTML output of process sheet (containing all the operations & the parameters in a table.)

The problem I am facing is related to Tool Diameter & Tool Corner Radius.

 

Let me first explain what output do I exactly want.

In the tool diameter column, I want either E or B prefix with diameter value. This will be decided based on the 'tool corner radius' value.

If the value is 0, the output should be something like 'EXX.X' where XX.X is a number.

& If the value is greater than 0, the output should be 'BXX.X'.

 

It's obvious that I gotta use If-else here.

 

I have tried multiple combinations & methods with If-else but I'm not able to get the output I'm expecting.

 

Attaching the code & the screenshot of the output.

Any help would be helpful.

 

Code (I am attaching only the related lines):

 

------------------------------------------------------------------------------------------------------------------------------

global mom_tool_diameter

global mom_tool_corner1_radius

 

#Format for the Variables

global var
proc Format3 {var} {

set var [format "E%.1f" $var]
return $var
}

 

global var
proc Format4 {var} {

set var [format "B%.1f" $var]
return $var
}

 

global var
proc Format5 {var} {

set var [format "R%.1f" $var]
return $var
}

 

#If-else statement for the tool diameter column. Using Format 3 for prefix E & Format 4 for prefix B.

if {$mom_tool_diameter == "0"} {

MOM_output_literal "<td width=\"64\" height=\"24\" valign=\"top\" style=\"border-width : 1px; border-color: #000000; border-style: solid;\"><p style=\" text-align: center; text-indent: 0px; padding: 0px 0px 0px 0px; margin: 0px 0px 0px 0px;\"><span style=\" font-size: 10pt; font-family: 'Arial', 'Helvetica', sans-serif; font-style: normal; font-weight: normal; color: #000000; background-color: transparent; text-decoration: none;\">[Format3 $mom_tool_diameter]</span></p></td>"
} else {

MOM_output_literal "<td width=\"64\" height=\"24\" valign=\"top\" style=\"border-width : 1px; border-color: #000000; border-style: solid;\"><p style=\" text-align: center; text-indent: 0px; padding: 0px 0px 0px 0px; margin: 0px 0px 0px 0px;\"><span style=\" font-size: 10pt; font-family: 'Arial', 'Helvetica', sans-serif; font-style: normal; font-weight: normal; color: #000000; background-color: transparent; text-decoration: none;\">[Format4 $mom_tool_diameter]</span></p></td>"
}

 

#Tool Corner Radius Column using Formt 5 for getting prefix R.

MOM_output_literal "<td width=\"28\" height=\"24\" valign=\"top\" style=\"border-width : 1px; border-color: #000000; border-style: solid;\"><p style=\" text-align: center; text-indent: 0px; padding: 0px 0px 0px 0px; margin: 0px 0px 0px 0px;\"><span style=\" font-size: 10pt; font-family: 'Arial', 'Helvetica', sans-serif; font-style: normal; font-weight: normal; color: #000000; background-color: transparent; text-decoration: none;\">[Format5 $mom_tool_corner1_radius]</span></p></td>"

 

------------------------------------------------------------------------------------------------------------------------------

Output.JPGI get prefix B for both 0 & positive values of Tool Corner Radius.

 

 

PS: If I replace the Format 3 & 4, I get E prefix with all the Tool Diameter values.

I think it's not taking the IF condition (I might be doing something wrong in the IF part). ELSE part is always correct.

 

Thanks for the help & Happy NEW YEAR.


Paras Raina, Technical Head, MSC Systems Pvt. Ltd. (India)
NX 12.0.2
Solid Edge 2019
7 REPLIES 7

Re: If-else statement - post Builder

Phenom
Phenom

I can't verify but are you sure that Nx accept "0" as tool diameter ?? That said...

I think there is an error with your condition , i'm not sure but $mom_tool_diameter can't equal to "0" but "0.000000..."

In this case , I'll wrote :

if {$mom_tool_diameter > 0} {
MOM_output_literal "... "none;\">[Format4 $mom_tool_diameter </span></p></td>"
} else {
MOM_output_literal "... "none;\">[Format3 $mom_tool_diameter]</span></p></td>"
}

Sometimes the nx mom variables puts "0.0000001..." for a written value to "0" (It's not maybe true for mom_tool_diameter).

If so , change the format of mom_tool_diameter according to your needs

e.g :

if {[format %.4f $mom_tool_diameter] > 0} {
...
} else {
...
}
Production: NX11.0.2.7,VERICUT 8.1.2
Development: Tcl/Tk, Gnuplot
www.adgroupe.com

Re: If-else statement - post Builder

Solution Partner Genius Solution Partner Genius
Solution Partner Genius

@mkn

 

Thanks for pointing out my mistake. I was actually so lost in the code, I totally overlooked the actual variable in IF statement.

You got it right. The tool dia obviously can never be zero.

What I needed there was $mom_tool_corner1_radius.

 

if {$mom_tool_corner1_radius == 0}

 This is what I needed for the condition.

 

Appreciate the help.

 

Best Regards,


Paras Raina, Technical Head, MSC Systems Pvt. Ltd. (India)
NX 12.0.2
Solid Edge 2019

Re: If-else statement - post Builder

Legend
Legend

Hello 

 

Please be careful wuith the variable $mom_tool_corner1_radius. This variable does not exists for all tools.

eg. Drilling Tools.

So you got an error in your if/else condition if the tool is an drilling tool.

Use

if {![info exists mom_tool_corner1_radius] || $mom_tool_corner1_radius == 0} {

instead

 

 

Regards

      

 

Re: If-else statement - post Builder

Gears Esteemed Contributor Gears Esteemed Contributor
Gears Esteemed Contributor

And another logic bomb....

Never rely on floating numbers being EXACTLY a number.  See here for an explanation:

http://floating-point-gui.de/

 

Siemens supplies a bunch of compare functions to allow comparison using a tolerance:

EQ_is_equal

EQ_is_zero

EQ_is_le

EQ_is_gt

etc.

(for a full list, open this file in a text editor and search on the above in %UGII_BASE_DIR%\MACH\resource\postprocessor\ugpost_base.tcl )

Or perhaps "ugpost_base_math.tcl" in the same folder.

 

I would do the comparison this way:

if {![info exists mom_tool_corner1_radius] || 
    [EQ_is_zero $mom_tool_corner1_radius]} {
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: If-else statement - post Builder

Siemens Legend Siemens Legend
Siemens Legend

The logical operands of  "==" & "!=" used in Tcl's IF condition are generally only good (& safe) for comparing strings.  "expr" should be used to compare numbers. Eg. if { [expr $var == 0] } { ... }.

 

How IF conditions would treat the numeric comparison seemed to have changed from version to version. You may find, in some version of Tcl, "if { "0.000" == "0" }" returns a "false". The output would become undesirable.  It's always safe to use "expr" for numeric comparisons.

Re: If-else statement - post Builder

Gears Esteemed Contributor Gears Esteemed Contributor
Gears Esteemed Contributor

I would still prefer use of the Siemens supplied EQ_is_* operators over "if { [expr $var == 0] }"

I believe the "==" in the "expr" command is EXACT (within the precision of a C/C++ "double" number) comparison.

 

I'm not sure how many "9"s cause the following comparisons to yield different true/false values, but I'm pretty sure there is a point where it will happen...and I'd bet the "EQ_is_equal" test has the result you would expect/want.

if { [expr .5 == .4999999999999263] }

if {[EQ_is_equal .5 .4999999999999263]}

 

 

 

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: If-else statement - post Builder

Siemens Legend Siemens Legend
Siemens Legend

Yes, for numerical comparison, it's recommended always use the EQ commands (they actually perform some "expr" operations underneath); they will take care of the issue with the numerical noise due to conversion of the numbers from their floating point representations within the computer.

Learn online





Solution Information