Skip to main content
Question

VariableRetriever works correctly?

  • February 26, 2018
  • 8 replies
  • 46 views

gtitz
Contributor
Forum|alt.badge.img+3
  • Contributor

Hi!

I set a variable in the Startup Python Script:

import fme
from datetime import datetime
fme.macroValues['workbench_started'] = datetime.now().strftime("%Y%m%d%H%M%S")

The first version of the workbench looks like this:

0684Q00000ArAXHQA3.jpg

This is the result - there is no current-date-time-value in the attribute _value:

0684Q00000ArAfQQAV.jpg

So, in my opinion the VariableRetriever didn't work correctly.

---------------------

Alternative solution, use the python caller to retrieve the variable and set attribute:

0684Q00000ArAdjQAF.jpg

This is the code of the PythonCaller:

import fme
import fmeobjectsdef processFeature(feature):
    feature.setAttribute("_value", fme.macroValues['workbench_started'])

This is the result:

0684Q00000ArAghQAF.jpg

It looks like the VariableRetriever isn't working properly.

Or did I make something wrong?

I have tried it in FME Desktop 2018.0 and FME Desktop 2017.1.2.0.

8 replies

Forum|alt.badge.img
  • February 26, 2018

Any reason not to use a Private User Parameter as a Scripted (Python)  called "workbench_started"

from datetime import datetime
return datetime.now().strftime("%Y%m%d%H%M%S")

Then just reference the User Parameter


david_r
Evangelist
  • February 26, 2018

The variables set using the VariableRetriever / VariableSetter aren't available from the Python API, unfortunately. As far as I know there are no methods for manipulating them using Python. See also here: https://knowledge.safe.com/questions/2263/python-global-variable.html

The dictionary "fme.macroValues" (and the global dictionary "FME_MacroValues") references the private and published parameters of the workspace, not the variables.

 


gtitz
Contributor
Forum|alt.badge.img+3
  • Author
  • Contributor
  • February 26, 2018
davidrich wrote:

Any reason not to use a Private User Parameter as a Scripted (Python)  called "workbench_started"

from datetime import datetime
return datetime.now().strftime("%Y%m%d%H%M%S")

Then just reference the User Parameter

Thanks for you reply, but sorry, I don't know what you mean?!

 


gtitz
Contributor
Forum|alt.badge.img+3
  • Author
  • Contributor
  • February 26, 2018
david_r wrote:

The variables set using the VariableRetriever / VariableSetter aren't available from the Python API, unfortunately. As far as I know there are no methods for manipulating them using Python. See also here: https://knowledge.safe.com/questions/2263/python-global-variable.html

The dictionary "fme.macroValues" (and the global dictionary "FME_MacroValues") references the private and published parameters of the workspace, not the variables.

 

Thanks! Over your link, I came to this site:

 

https://knowledge.safe.com/questions/2263/python-global-variable.html

 

I think, I will set a global variable by the startup python script. In the workflow I will read the global variable with a python caller and set the value to an attribute of the features.

 

 


david_r
Evangelist
  • February 26, 2018
gtitz wrote:
Thanks! Over your link, I came to this site:

 

https://knowledge.safe.com/questions/2263/python-global-variable.html

 

I think, I will set a global variable by the startup python script. In the workflow I will read the global variable with a python caller and set the value to an attribute of the features.

 

 

If you simply need the timestamp for when the workspace started, here's a maybe simpler solution:

 

  1. Create a private parameter of type "Scripted (Python"
  2. Inside the private parameter, insert the code suggested by @davidrich
  3. In your workspace, use the ParameterFetcher whenever you want to reference the startup timestamp.
This way you won't have to use Python global variables.

Forum|alt.badge.img
  • February 26, 2018
gtitz wrote:
Thanks for you reply, but sorry, I don't know what you mean?!

 

Then change type to Scripted (Python)

 

Name as "Workbench_started"

 

and paste the code in the Value

 

 

then should be able to access "Workbench_started" anywhere in the workbench

gtitz
Contributor
Forum|alt.badge.img+3
  • Author
  • Contributor
  • February 26, 2018
davidrich wrote:

Then change type to Scripted (Python)

 

Name as "Workbench_started"

 

and paste the code in the Value

 

 

then should be able to access "Workbench_started" anywhere in the workbench
Ah, great! "Scripted (Python)" was the hint I needed! Thanks! :)

 


gtitz
Contributor
Forum|alt.badge.img+3
  • Author
  • Contributor
  • February 26, 2018
david_r wrote:
If you simply need the timestamp for when the workspace started, here's a maybe simpler solution:

 

  1. Create a private parameter of type "Scripted (Python"
  2. Inside the private parameter, insert the code suggested by @davidrich
  3. In your workspace, use the ParameterFetcher whenever you want to reference the startup timestamp.
This way you won't have to use Python global variables.
Yes, you are right! That's the better solution. Thanks! :)

 


Reply


Cookie policy

We use cookies to enhance and personalize your experience. If you accept you agree to our full cookie policy. Learn more about our cookies.

 
Cookie settings