Skip to main content
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

 

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
Or, defining a scripted parameter could be more suitable solution in your case. See also these links: http://docs.safe.com/fme/html/FME_Workbench/Default.htm#Parameters/scripted_python_tcl.htm

 

http://fmepedia.safe.com/articles/How_To/Python-and-FME-Basics#heading_toc_j_3 http://fmepedia.safe.com/AnswersQuestionDetail?id=906a0000000cld2AAA

 

http://fmepedia.safe.com/AnswersQuestionDetail?id=906a0000000con3AAA
Hey Takashi,

 

 

thank you very much for your answer and your examples.

 

 

I used the scripted parameter and it works!

 

 

Regards,

 

 

Isabell

 

 


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.macroValuese'PARAMS'])
return paramsv'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()


Reply