cancel
Showing results for 
Search instead for 
Did you mean: 

Post Builder ask expression

Pioneer
Pioneer

Hello all,

 

I have been using the following code for a while now to output the value of an expression at the end of my program. If there is no expression that is specified in the code(in NX8.5), it would ignore and move on. Now, when testing NX10, I am getting an "Undefined Expression" error, when no expression is there. Anybody know why?

 

Thanks in advance,

Ron

Windows 7 64-bit

NX8.5, testing NX10

global mom_sys_control_in mom_sys_control_out MOM_ask_ess_exp_value


set co $mom_sys_control_out
set ci $mom_sys_control_in


catch [set expVal [MOM_ask_ess_exp_value EXPRESSION1]]
if {[info exists expVal ] &&
![string match "No such variable defined in Expression" $expVal ]} {
MOM_output_literal "$co\EXPRESSION1 = $expVal\ $ci"
}

 

14 REPLIES

Re: Post Builder ask expression

Phenom
Phenom

I think someone already mentioned (in a thread) the need to put catch around it after a particular version of NX. Expressions (function of) has been enhanced in the last NX versions. I think the post can write them now.

NX10.03
Windows 7 Pro

Re: Post Builder ask expression

Esteemed Contributor
Esteemed Contributor

Looks like something I'll have to remember to test in our upgrade.

 

Try adding a "MOM_output_text expVal = $expVal" (or MOM_output_to_listing_device) to see what it is really returning, and adapt your logic to suit.

 

Ken

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: Post Builder ask expression

Pioneer
Pioneer

Ken,

 

I don't get any output when I add your suggested code. I added in multiple different locations in the code. Where would you add it to get the value of expVal to output? 

 

Thanks,

Ron

Re: Post Builder ask expression

Esteemed Contributor
Esteemed Contributor

Maybe I should have applied more thought...

Try something like this for an expression that doesn't exist.

Then adapt logic as needed

global mom_sys_control_in mom_sys_control_out MOM_ask_ess_exp_value


set co $mom_sys_control_out
set ci $mom_sys_control_in

set exp_name "EXPRESSION1"

catch [set expVal [MOM_ask_ess_exp_value $exp_name]]
if {[info exists expVal]} {
     # TODO: add logic here to parse returned value for "does not exist" test string
MOM_output_literal "$co\$exp_name = $expVal\ $ci" } else { MOM_output_literal "$co\$exp_name does not exist?\ $ci" }

 

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: Post Builder ask expression

Esteemed Contributor
Esteemed Contributor

BTW, global is meant for variables, not for functions, so remove MOM_ask_ess_exp_value from the global variable declaration.

Stefan Pendl, Systemmanager CAx, HAIDLMAIR GmbH
Production: NX10.0.3, VERICUT 8.0, FBM, MRL 3.1.4 | TcUA 10.1 MP7 Patch 0 (10.1.7.0) | TcVis 10.1
Development: VB.NET, Tcl/Tk    Testing: NX12.0

How to Get the Most from Your Signature in the Community

Re: Post Builder ask expression

Pioneer
Pioneer

Thanks for the help guys, but still no dice. I also tried a string of "Undefined expression" also. That error was listed in the syslog.

 

global mom_sys_control_in mom_sys_control_out


set co $mom_sys_control_out
set ci $mom_sys_control_in


set exp_name "EXPRESSION1"

catch [set expVal [MOM_ask_ess_exp_value $exp_name]]
if {[info exists expVal ] &&
![string match "No such variable defined in Expression" $expVal ]} {
    MOM_output_literal "$co\Expression1 = $expVal\ $ci"
} else {
    MOM_output_literal "$co\$exp_name does not exist?\ $ci"
}

 

Re: Post Builder ask expression

Esteemed Contributor
Esteemed Contributor

Take out the "string match" in the first expression?

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: Post Builder ask expression

Pioneer
Pioneer

Won't let me. "Custom command error"

Re: Post Builder ask expression

Phenom
Phenom

I would do it this way:

 

global mom_sys_control_in mom_sys_control_out


set co $mom_sys_control_out
set ci $mom_sys_control_in

set exp_name "EXPRESSION1"

catch {set expVal [MOM_ask_ess_exp_value $exp_name]}
if {[info exists expVal ]} {
    MOM_output_literal "$co\Expression1 = $expVal\ $ci"
} else {
    MOM_output_literal "$co\$exp_name does not exist?\ $ci"
}

 I think that curly braces are better for catch and you should just have to see if anything came back from MOM_ask_ess_exp_val call.

NX10.03
Windows 7 Pro

Learn online





Solution Information