Skip to main content

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.

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

:


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

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.


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.
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!

 

 


@angela

The problem with the expression is the if and return.

It should be

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


@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.

 


@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

 

 

 

 


@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.

 

 


@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... 😉

Reply