Question

Arithmetic Python/TCL in private parameters

  • 9 October 2015
  • 6 replies
  • 2 views

Hi,

 

I am trying to do something which I'm sure is pretty basic but struggling

 

I've got a public parameter (cellres) which refers to the cell resolution of an output ratser and I'm trying to use this to calculate the number of rows/colums, based on the maximum extents (max_X/max_Y).

 

I'm struggling to write the python or TCL - essentially I just want to do (max_X / cellres)?

 

It appears to be just concatenating the two parameters rather than returning a value

 

Thanks

 

Ed

6 replies

Userlevel 2
Badge +17
Hi Ed,

 

 

Could you please show us the script that you have defined in the scripted parameter?

 

 

Takashi
Hi Takashi

 

I tried using a TCL expression and used expr(1220000/$FME_MacroValues(cellres))

 

I've never used TCL before so I suspect I'm doing something entirely wrong

 

Thanks,

 

Ed
Userlevel 2
Badge +17
Try this expression:

 

return [expr 1220000/$FME_MacroValues(cellres)]

 

 

or, if you want to get a decimal number always:

 

return [expr 1220000.0/$FME_MacroValues(cellres)]

 

 

See here to learn more about Tcl commands. (https://www.tcl.tk/man/tcl8.5/TclCmd/contents.htm)
Userlevel 2
Badge +17
and Tcl Tutorial is here. (https://www.tcl.tk/man/tcl8.5/tutorial/tcltutorial.html)
Thanks Takashi, extremely helpful as always :)
Userlevel 4
For reference, here is the same using Python:

 

 

return 1220000.0 / float(FME_MacroValues['cellres'])

 

 

Just make sure that cellres <> 0 (goes for TCL too, I assume).

 

 

David

Reply