Skip to main content
Using the following within EXCEL or CSV-file works with STRINGS:

 

 

MYNEWVALUE = @Evaluate(ereturn {@Value(MYATTRIBUTE1)_@Value(MYATTRIBUTE2)}])

 

 

However when I try to do arithmetic operations I only get the letters and not the calculations. Any ideas?

 

 

Doing this:

 

 

MYNEWVALUE = @Evaluate(vreturn {@Value(MYNUMBERATT1)-@Value(MYNUMBERATT2)}])

 

 

With attributes

 

MYNUMBERATT1 = 10

 

MYNUMBERATT2 = 1

 

 

gives: MYNEWVALUE = 10-1

 

 

And NOT the desirec MYNEWVALUE = 9
Hi Sig,

 

 

Try "expr" command instead of "return".

 

-----

 

@Evaluate(aexpr {@Value(MYNUMBERATT1)} - {@Value(MYNUMBERATT2)}])

 

-----

 

https://www.tcl.tk/man/tcl8.5/TclCmd/expr.htm

 

 

Takashi
Or just evaluate the expression. Probably this also works.

 

-----

 

@Evaluate(@Value(MYNUMBERATT1) - @Value(MYNUMBERATT2))

 

-----
Great help as always Takashi! 
Tho Takashi is correct, [expr someexpression] to do expressions (lol) is the way to go,

 

 

u also could have added an @Evaluation over your new value, or added an "=" in front of it.

 

 

Because your result was an "unevaluated" expression. Wich is the result of using sreturn ..]

 

 

btw it is expr { yourexpression}] You can save some braces.
Gio is right. Curly braces are not essential in this case, because MYNUMBERATT1 and MYNUMBERATT2  should be numeric representations and they cannot contain space characters. And the expression in my first post was no good. It would fail if the space behind - operator was omitted and MYNUMBERATT2 was negative (i.e. begins with minus sign).

 

These are right. Spaces before and behind - operator can be omitted.

 

-----

 

@Evaluate(uexpr {@Value(MYNUMBERATT1) - @Value(MYNUMBERATT2)}])

 

-----

 

@Evaluate(aexpr @Value(MYNUMBERATT1) - @Value(MYNUMBERATT2)])

 

-----

 

@Evaluate(@Value(MYNUMBERATT1) - @Value(MYNUMBERATT2))

 

-----

 

Thanks for the attention, Gio.

 

 

In addition, if the attribute values weren't numeric representations, the workspace would fail even though the expression was surrounded by curly braces. If it cannot be guaranteed that they are always numeric, you should validate them before math operation to prevent failure. Use the AttributeClassifier beforehand to filter out invalid features, or create conditional value with Tcl commands. For example:

 

-----

 

@Evaluate( if {@string is double -strict {@Value(MYNUMBERATT1)}] && )string is double -strict {@Value(MYNUMBERATT2)}]} {expr @Value(MYNUMBERATT1) - @Value(MYNUMBERATT2)} else {return "Invalid"}])

 

-----

Reply