Skip to main content
Question

Set Published Parameters in a Python Startup Script

  • September 27, 2013
  • 4 replies
  • 173 views

Hello!

 

 

I tried to set a published Parameter in the Python startup script, but the parameter changes just in the dictionary (I think), but not in the workspace.

 

 

Is it possible to set a published parameter in the python startup script?

 

 

Here's my Python Code:

 

 

def ReadParameter():

 

    ParameterFile = open(r'R:\\212_TIM\\Konzept\\TIM_Auskunft\\FME_Migration\\LOG\\ParameterFile.txt','r')

 

    for line in ParameterFile:

 

        key, value = line.split(' = ')

 

        if key == 'CountStart':

 

           return int(value)

 

    return 'Konnte Id nicht finden'

 

 

HIS_ID_intern = ReadParameter()

 

d1 = {'HIS_ID' : HIS_ID_intern}

 

FME_MacroValues.update(d1)

 

 

Thanks for your help!

 

 

Regards,

 

 

Isabell

 

4 replies

takashi
Evangelist
  • September 27, 2013
Hi Isabell,

 

 

Parameter values are static, we can not change them at run-time (including startup / shutdown process) unfortunately.

 

I think that using global variables could be a workaround.

 

See also this Q&A:

 

Python Shutdown Best Practise - Global Variables + Published Parameters http://fmepedia.safe.com/AnswersQuestionDetail?id=906a0000000cgTZAAY

 

 

Takashi

takashi
Evangelist
  • September 28, 2013

  • Author
  • September 30, 2013
Hey Takashi,

 

 

thank you very much for your answer and your examples.

 

 

I used the scripted parameter and it works!

 

 

Regards,

 

 

Isabell

 

 


arjanboogaart
Participant
Forum|alt.badge.img

I'm currently working on a script that loads a lot of user parameters from a csv or json, and also wanted this to work.

 

It doesn't appear to be possible in the startup script, as it is executed after the parameters are resolved.

However, there is a workaround using scripted parameters. Scripted parameters are resolved from top to bottom (it appears), so a scripted parameter can use values from parameters above it.

You can create a parameter at the top named PARAM, which can return arbitrary data using python.

For example:

return {'BUFFER_DISTANCE'2'RETICULATE_SPLINES'True}

Then, in the parameter BUFFER_DISTANCE, I can add the following code to retrieve the value:

import fme
params = eval(fme.macroValues['PARAMS'])
return params['BUFFER_DISTANCE']

Note that a parameter is always a string, so to be able to use it as dictionary we need to call eval() on it.

Warning: eval() can execute arbitrary python code. Make sure you NEVER call it directly on user input. If you want to use user input, use import json with json.loads()


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