Skip to main content
Question

How can I assign user parameters via a file? I have a large number of parameters and they all need to be pre-assigned. However, the content of the parameters can change. Therefore a variable solution is needed

  • September 18, 2023
  • 6 replies
  • 22 views

fbeginner
Contributor
Forum|alt.badge.img+2
How can I assign user parameters via a file? I have a large number of parameters and they all need to be pre-assigned. However, the content of the parameters can change. Therefore a variable solution is needed

6 replies

nielsgerrits
VIP
Forum|alt.badge.img+54

Yes you can, using a Python Scripted Parameter.

 

Create an .ini file, for example FmeConfig.ini with the following contents.

[Section1]
Setting1 = Value1
Setting2 = Value2
 
[Section2]
Setting3 = Value3
Setting4 = Value4
 
[Section3]
Setting5 = Value5
Setting6 = Value6

In FME, create a Scripted Parameter, Section1_Setting1.

import configparser
config = configparser.ConfigParser()
config.read(r'C:\TMP\FmeConfig.ini')
return config.get('Section1''Setting1')

This wil set the parameter Section1_Setting1 to Value1.

 

If you have a lot of parameters, this will take some time to set up, but it will do what you asked for.


fbeginner
Contributor
Forum|alt.badge.img+2
  • Author
  • Contributor
  • September 19, 2023

Hello nielsgerrits,

Thank you for the quick reply. Das Script works nice. But now I have a new problem. 

Sorry, I am just a beginner. When I pass words with umlauts (ä, ü, ö etc.) as values, they are not displayed correctly. Also an AttributeEncoder does not translate the values to UTF8. 

Do you have a solution here too. Thank for your help.


nielsgerrits
VIP
Forum|alt.badge.img+54
fbeginner wrote:

Hello nielsgerrits,

Thank you for the quick reply. Das Script works nice. But now I have a new problem. 

Sorry, I am just a beginner. When I pass words with umlauts (ä, ü, ö etc.) as values, they are not displayed correctly. Also an AttributeEncoder does not translate the values to UTF8. 

Do you have a solution here too. Thank for your help.

Ah encoding, can you try if the following code works for you?

import configparser
config = configparser.ConfigParser()
with open(r'C:\TMP\FmeConfig.ini', encoding='utf-8'as f:
    config.read_file(f)
return config.get('Section1''Setting1')

 


fbeginner
Contributor
Forum|alt.badge.img+2
  • Author
  • Contributor
  • September 19, 2023

Hi nielsgerrits,

great, that's the solution. You are the best. Thanks


nielsgerrits
VIP
Forum|alt.badge.img+54
fbeginner wrote:

Hi nielsgerrits,

great, that's the solution. You are the best. Thanks

To be hones, I only implemented an ChatGPT answer, but if it works, it works :)


fbeginner
Contributor
Forum|alt.badge.img+2
  • Author
  • Contributor
  • September 19, 2023

OK good idea, next time I'll also try chatGPT first, but if not I'll be back in the forum. Thanks 🤔


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