Skip to main content
Solved

Dynamic listing of parameter names


dustin
Influencer
Forum|alt.badge.img+30

One thing I prefer to do when building a new FME tool is to log the input parameters in a startup python script in order to facilitate debugging when things go wrong. A sample of the code I use is below.

import fmeobjects
 
fmeobjects.FMELogFile().logMessageString("Input parameter 1: ") + FME_MacroValues["parameter1"], fmeobjects.FME_INFORM)
fmeobjects.FMELogFile().logMessageString("Input parameter 2: ") + FME_MacroValues["parameter2"], fmeobjects.FME_INFORM)

This has worked great for a long time, however it's cumbersome because I need to manually enter the names of the parameters. I'm curious if there is a method for returning the names of parameters dynamically in the startup python script, and then loop through them to include in the log file. If this is possible, I could keep my startup script the same between all tools and simply copy it into new tools without having to modify.

 

Best answer by saraatsafe

Hi @dustin​, 

You can try iterating through macrovalues and excluding most of the irrelevant FME-specific values. For example: 

import fme, fmeobjects
 
for k, v in fme.macroValues.items():
    if k.startswith("FME_"):
        continue
    fmeobjects.FMELogFile().logMessageString(f"{k}: {v}")

Hope this helps!

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

2 replies

saraatsafe
Safer
Forum|alt.badge.img+9
  • Safer
  • Best Answer
  • July 31, 2023

Hi @dustin​, 

You can try iterating through macrovalues and excluding most of the irrelevant FME-specific values. For example: 

import fme, fmeobjects
 
for k, v in fme.macroValues.items():
    if k.startswith("FME_"):
        continue
    fmeobjects.FMELogFile().logMessageString(f"{k}: {v}")

Hope this helps!


dustin
Influencer
Forum|alt.badge.img+30
  • Author
  • Influencer
  • July 31, 2023
saraatsafe wrote:

Hi @dustin​, 

You can try iterating through macrovalues and excluding most of the irrelevant FME-specific values. For example: 

import fme, fmeobjects
 
for k, v in fme.macroValues.items():
    if k.startswith("FME_"):
        continue
    fmeobjects.FMELogFile().logMessageString(f"{k}: {v}")

Hope this helps!

@saraatsafe​ 

 

Thank you! Brilliant! This is what I came up with:

import fme,fmeobjects
fmeobjects.FMELogFile().logMessageString("---------\n------------------\n---------------------------\n------------------------------------\n", fmeobjects.FME_INFORM)
 
for k,v in sorted(fme.macroValues.items()):
    if k.startswith("1_"):
        fmeobjects.FMELogFile().logMessageString(f"{k}: {v}")
        
fmeobjects.FMELogFile().logMessageString("------------------------------------\n---------------------------\n------------------\n---------\n", fmeobjects.FME_INFORM)

I'll just need to make sure I prefix my  parameter identifiers with "1_". And the result:

image


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