Skip to main content
Solved

How do you get expressions to evaluate and return a result in Attribute Manager?

  • September 12, 2017
  • 10 replies
  • 228 views

Forum|alt.badge.img

I'm trying to create an attribute ("incorporated") whose value is 0 or 1, depending on the value of another attribute ("Code"). I'm trying to do this in Attribute Manager. But I can't seem to get it to evaluate. I've tried many different permutations of the expression. The attempt shown in the attachment uses Python syntax highlighting which I would assume means it would be interpreted as Python code. Anyway, it doesn't work, as you can see in the breakpoint data.

Best answer by courtney_m

In the AttributeManager, click the incorporated line. Then click on the down arrow in the Attribute Value box. Click Conditional Value...

This will open the conditional value dialog, where you can define your if-then statement. Double-click on the blank next to If. Then type in your first condition. Note that Output Value is the value that you are assigning to incorporated when the test clause passes.

You can do this many times, to create all possible values for incorporated, or just set the Else value

:

This post is closed to further activity.
It may be an old question, an answered question, an implemented idea, or a notification-only post.
Please check post dates before relying on any information in a question or answer.
For follow-up or related questions, please post a new question or idea.
If there is a genuine update to be made, please contact us and request that the post is reopened.

10 replies

courtney_m
Contributor
Forum|alt.badge.img+19
  • Contributor
  • 127 replies
  • Best Answer
  • September 12, 2017

In the AttributeManager, click the incorporated line. Then click on the down arrow in the Attribute Value box. Click Conditional Value...

This will open the conditional value dialog, where you can define your if-then statement. Double-click on the blank next to If. Then type in your first condition. Note that Output Value is the value that you are assigning to incorporated when the test clause passes.

You can do this many times, to create all possible values for incorporated, or just set the Else value

:


fmelizard
Safer
Forum|alt.badge.img+20
  • Safer
  • 3719 replies
  • September 12, 2017

In the AttributeManager, click the incorporated line. Then click on the down arrow in the Attribute Value box. Click Conditional Value...

This will open the conditional value dialog, where you can define your if-then statement. Double-click on the blank next to If. Then type in your first condition. Note that Output Value is the value that you are assigning to incorporated when the test clause passes.

You can do this many times, to create all possible values for incorporated, or just set the Else value

:

We also have an article on Conditional Values

Forum|alt.badge.img
  • 12 replies
  • September 12, 2017

Great, thanks that works. Somehow I hadn't seen that option!

I'm still curious about how, when you enter an expression using the syntax of say, for instance, python, how that works. Is the fact that it's python detected via the syntax, meaning it's then interpreted as python? Would love to see some examples.


courtney_m
Contributor
Forum|alt.badge.img+19
  • Contributor
  • 127 replies
  • September 12, 2017

Great, thanks that works. Somehow I hadn't seen that option!

I'm still curious about how, when you enter an expression using the syntax of say, for instance, python, how that works. Is the fact that it's python detected via the syntax, meaning it's then interpreted as python? Would love to see some examples.

As far as I know, the syntax highlighting does not change the way the text is evaluated, it is merely a tool to help the user. If you want to run a python script, I would use the PythonCaller, or create a Python Scripted Parameter.

Forum|alt.badge.img
  • 12 replies
  • September 12, 2017
As far as I know, the syntax highlighting does not change the way the text is evaluated, it is merely a tool to help the user. If you want to run a python script, I would use the PythonCaller, or create a Python Scripted Parameter.
Okay, thanks Courtney!

 

 


gio
Contributor
Forum|alt.badge.img+15
  • Contributor
  • 2252 replies
  • September 14, 2017

@angela

The problem with the expression is the if and return.

It should be

@Value(CODE)=="CN":1:0


takashi
Celebrity
  • 7843 replies
  • September 14, 2017

@angela

The problem with the expression is the if and return.

It should be

@Value(CODE)=="CN":1:0

@gio, I remember that the ? : operator taking string comparison as the first operand had worked in the old days, but I don't think it works with string comparison in the current version of FME.

 


gio
Contributor
Forum|alt.badge.img+15
  • Contributor
  • 2252 replies
  • September 14, 2017

@angela

The problem with the expression is the if and return.

It should be

@Value(CODE)=="CN":1:0

@takashi

 

 

Yes, I forgot the questionmark.

 

Should be @Value(CODE)==?"CN":1:0

 

 

It doesn't no more? I, see

 

Well then we have no choice but to use

 

[regexp {CN} @Value(CODE)] !=0?1:0

 

 

 

 


takashi
Celebrity
  • 7843 replies
  • September 15, 2017

@angela

The problem with the expression is the if and return.

It should be

@Value(CODE)=="CN":1:0

It seems that the @Evaluate function evaluates a Tcl expression in fact. Interesting but I would not recommend use this functionality, since it's not documented anywhere and therefore it could be deprecated at some point in the future.

 

 


gio
Contributor
Forum|alt.badge.img+15
  • Contributor
  • 2252 replies
  • September 15, 2017

@angela

The problem with the expression is the if and return.

It should be

@Value(CODE)=="CN":1:0

I use regexp in arithmetic- and text editors all the time.

 

It would be a great loss if it were removed.

 

I see no logic in doing so.

 

It would cause workspaces to need more transformers then required.

 

FME uses tcl a lot anyway, so why would it become deprecated?

 

 

In fact before there was a "Conditional Value" I did this using expressions.

 

The @Evaluate() always did evaluate tcl expressions, I can't imangine why that would surprise you....

 

 

Look at the stringsearcher, which now (since some 2016 version) can do what I used to do using attributecreators evaluating regexp in string-mode, boolean-mode and index-mode using a custom to loop trough all the matches. Because using regexp in tcl would allow me to use switches. (example is still on the forum, so you can see how long ago that was..)

 

Great improvement. Alas, still can't use switches.

 

 

I could go on..i guess... ;)