Skip to main content

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.macroValuesa'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.

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


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.

 


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

 


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.

 

 


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

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! :)

 


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