Skip to main content
Solved

Accessing MacroValues


jdh
Contributor
Forum|alt.badge.img+28
  • Contributor

Is it better practice to use 

 

import fme
param = fme.macroValues[‘parameterName’]

or

import fmeobjects
param = FME_MacroValues[‘parameterName’]

in Python scripted parameters and why?

Best answer by daveatsafe

Hi @jdh,

FME_MacroValues is still available for backwards compatibility, but we would recommend that fme.macroValues be used instead.

View original
Did this help you find an answer to your question?

14 replies

david_r
Celebrity
  • October 16, 2018

I've noticed that since FME 2018 I've been getting sporadical errors when importing fmeobjects in startup and shutdown scripts on FME Server. My guess is that this is somehow related to how the server engines seem to share session objects between jobs.

So recently I've adopted the following rule, which seems to work for all my use cases.

Startup/shutdown scripts + scripted parameters

import fme
param = fme.macroValues[‘parameterName’]

PythonCaller / PythonCreator

import fmeobjects
param = FME_MacroValues[‘parameterName’]

It would be great if someone from Safe could chime in with the official best-practices.


jdh
Contributor
Forum|alt.badge.img+28
  • Author
  • Contributor
  • October 16, 2018
david_r wrote:

I've noticed that since FME 2018 I've been getting sporadical errors when importing fmeobjects in startup and shutdown scripts on FME Server. My guess is that this is somehow related to how the server engines seem to share session objects between jobs.

So recently I've adopted the following rule, which seems to work for all my use cases.

Startup/shutdown scripts + scripted parameters

import fme
param = fme.macroValues[‘parameterName’]

PythonCaller / PythonCreator

import fmeobjects
param = FME_MacroValues[‘parameterName’]

It would be great if someone from Safe could chime in with the official best-practices.

That's my general rule of thumb too, but as I was preparing some training material it occurred to me that I had no real basis for that, and figured I should ask.

 

 


david_r
Celebrity
  • October 16, 2018
jdh wrote:
That's my general rule of thumb too, but as I was preparing some training material it occurred to me that I had no real basis for that, and figured I should ask.

 

 

Knowing that you do the same thing is a relief ;-)

 

Hopefully Safe can give us the official explanation here.

jdh
Contributor
Forum|alt.badge.img+28
  • Author
  • Contributor
  • October 16, 2018
@DaveAtSafe, any thoughts?

 


daveatsafe
Safer
Forum|alt.badge.img+19
  • Safer
  • Best Answer
  • October 16, 2018

Hi @jdh,

FME_MacroValues is still available for backwards compatibility, but we would recommend that fme.macroValues be used instead.


jdh
Contributor
Forum|alt.badge.img+28
  • Author
  • Contributor
  • October 16, 2018
daveatsafe wrote:

Hi @jdh,

FME_MacroValues is still available for backwards compatibility, but we would recommend that fme.macroValues be used instead.

Just for Startup/shutdown scripts + scripted parameters, or in general (PythonCaller/Creator included)?

 

 


takashi
Influencer
  • October 16, 2018
daveatsafe wrote:

Hi @jdh,

FME_MacroValues is still available for backwards compatibility, but we would recommend that fme.macroValues be used instead.

Hi @DaveAtSafe, if you would recommend that fme.macroValues always be used rather than FME_MacroValues, please modify the script editor for the PythonCaller/Creator and some relevant documentations (e.g. here) in which FME_MacroValues is still used.

 


daveatsafe
Safer
Forum|alt.badge.img+19
  • Safer
  • October 16, 2018
takashi wrote:
Hi @DaveAtSafe, if you would recommend that fme.macroValues always be used rather than FME_MacroValues, please modify the script editor for the PythonCaller/Creator and some relevant documentations (e.g. here) in which FME_MacroValues is still used.

 

Hi @takashi,

 

Thanks for catching that. I have created a problem report to have that changed to fme.macroValues instead.

 


takashi
Influencer
  • October 17, 2018
daveatsafe wrote:
Hi @takashi,

 

Thanks for catching that. I have created a problem report to have that changed to fme.macroValues instead.

 

Thanks for filing the PR!

 

 


fmelizard
Safer
Forum|alt.badge.img+18
  • Safer
  • October 18, 2018
david_r wrote:

I've noticed that since FME 2018 I've been getting sporadical errors when importing fmeobjects in startup and shutdown scripts on FME Server. My guess is that this is somehow related to how the server engines seem to share session objects between jobs.

So recently I've adopted the following rule, which seems to work for all my use cases.

Startup/shutdown scripts + scripted parameters

import fme
param = fme.macroValues[‘parameterName’]

PythonCaller / PythonCreator

import fmeobjects
param = FME_MacroValues[‘parameterName’]

It would be great if someone from Safe could chime in with the official best-practices.

I'm not sure if this was what you're looking for, but for sure for startup and shutdown I'd consider it dangerous to use FME Objects in there. The reason is that at startup/shutdown the whole FME system is not yet available really.  So I like "import fme" there. For PythonCaller/Creator, I don't think there's really any diff but if you want to work with features etc then it feels like "import fmeobjects" sets you up for success better.

 

 

Remember, though, I'm an old school Tcl guy and Python wannabee-pretender.

 

 


takashi
Influencer
  • October 18, 2018
david_r wrote:

I've noticed that since FME 2018 I've been getting sporadical errors when importing fmeobjects in startup and shutdown scripts on FME Server. My guess is that this is somehow related to how the server engines seem to share session objects between jobs.

So recently I've adopted the following rule, which seems to work for all my use cases.

Startup/shutdown scripts + scripted parameters

import fme
param = fme.macroValues[‘parameterName’]

PythonCaller / PythonCreator

import fmeobjects
param = FME_MacroValues[‘parameterName’]

It would be great if someone from Safe could chime in with the official best-practices.

By the way, FME_MacroValues is not a member of the fmeobjects module, you can access it without importing the fmeobjects module. I think that discussing on "fme.macroValues vs. FME_MacroValues" is slightly different from discussing on "fme module and fmeobjects module".

 

 


bruceharold
Contributor
Forum|alt.badge.img+17
  • Contributor
  • June 20, 2019
daveatsafe wrote:

Hi @jdh,

FME_MacroValues is still available for backwards compatibility, but we would recommend that fme.macroValues be used instead.

I'm still seeing the legacy behavior in 2019, at least in Data Interoperability.

i.e. FME_MacroValues


lifalin2016
Contributor
Forum|alt.badge.img+29
  • Contributor
  • July 3, 2020
daveatsafe wrote:

Hi @jdh,

FME_MacroValues is still available for backwards compatibility, but we would recommend that fme.macroValues be used instead.

Still not fixed in 2020.0


raymondbrunner
Contributor
Forum|alt.badge.img+11

As I worked to resolve errors with attempting to reference a User Parameter from within a Python Scripted User Parameter, I discovered this thread.  (Thank you, FME Community!)

When I double-clicked on a user parameter (‘DAYS_PRIOR’) in version 2023.2.1 (build 23774) within the Python Scripted​ Configuration interface, FME Form inserted:  FME_MacroValues['DAYS_PRIOR']

In order to get the scripted parameter to function properly, I ended up changing the call to: fme.macroValues['DAYS_PRIOR']

I also had to explicitly import the fme library.


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