Solved

Accessing MacroValues

  • 15 October 2018
  • 13 replies
  • 166 views

Badge +22
  • Contributor
  • 1961 replies

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?

icon

Best answer by daveatsafe 16 October 2018, 21:52

View original

13 replies

Userlevel 5

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.

Badge +22

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.

 

 

Userlevel 5
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.
Badge +22
@DaveAtSafe, any thoughts?

 

Userlevel 2
Badge +17

Hi @jdh,

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

Badge +22

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

 

 

Userlevel 3
Badge +17

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.

 

Userlevel 2
Badge +17
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.

 

Userlevel 3
Badge +17
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!

 

 

Userlevel 4
Badge +13

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.

 

 

Userlevel 3
Badge +17

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

 

 

Badge +16

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

Userlevel 1
Badge +22

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

Reply