The idea is to get the two values: $my_name, $my_status because for the moment, they both are received via user input. In this way, the user would have less data to input. This is the desired outcome.
I always know that the list mappes the values correctly through the index, so I can always deduct the latter values. (In this example it would be idx[1]).
In FME i get "failed to evaluate Pyton script 'def ParamFunc()'".
Can anyone help me out to make this work?
Best answer by takashi
Hi,
As David mentioned, the order of parameter definitions is important. If you need to refer to other parameter (e.g. code) from the scripted parameter, the referred parameter should be defined before the script. i.e. upper than the scripted parameter on the Navigator tree. And, maybe you should escape the back slashes, like this. src = 'C:\\\\local\\\\tmp.shp' or use slashes instead. src = 'C:/local/tmp.shp' If you want to create multiple parameters in a script, consider defining a Scripted (Tcl) Parameter. This script example defines two parameters (i.e. macros) named MY_NAME and MY_STATE, and also returns a path string. --- # Scripted (Tcl) Prameter Example set code $FME_MacroValues(code) set index [lsearch -exact {"ab" "ca" "ny"} $code] if {$index < 0} { return "unexpected code" } set name [lindex {"Alex" "Carl" "Nelly"} $index] set state [lindex {"aall" "cast" "noo"} $index] puts "MACRO MY_NAME $name" puts "MACRO MY_STATE $state" return [format {C:\\local\\%s\\%s_%s\\files\\target.shp} $code $name $state] --- Although MY_NAME and MY_STATE will not appear in the parameter list of workbench interface, those can be accessed indeed. e.g. FME_MacroValues['MY_NAME'] in a PythonCaller. As far as I know, Scripted (Tcl) Parameter is the only way to append macros by scripting. Python cannot do it.
Did this help you find an answer to your question?
This post is closed to further activity.
It may be a question with a best answer, an implemented idea, or just a post needing no comment.
If you have a follow-up or related question, please post a new question or idea.
If there is a genuine update to be made, please contact us and request that the post is reopened.
Hi Robert, You can not assign any value to FME_MacroValues. I guess that the error occurred in a Scripted Prameter. If you are trying to define a Scripted Parameter, you should return a value from the script. The returned value will be the parameter value. For example, if you define this script for a Scripted Parameter named "status", $(status) will be the expected value. ----- n = FME_MacroValues['code'] code = ['ab', 'ca', 'ny'] status = ['aall', 'cast', 'noo'] return status[code.index(n)] if n in code else '' -----
It works in the previouse version, where I input all the variables from the command line. It seems it does not bring in the returned value to compute the paths.
I know that, unfortunately I cannot post the entire code, so I am going to try and mimic it:
The src is a scripted param, and it is the same as it was before. It computes the path using the same variables and it is located as before, in the Private Parameters section.
So, I have 3 PrivateParams:
src (a path composed out of known folders + the values returned by my_name and my_state prameters)
my_name (using the pattern from your example)
my_state (using the pattern from your example)
The result is a huge error, repeating the <space>FME_MacroValues<openbracket><apos> tags all over. Between them I can see values from my dictionary reference.
Make sure that the order of the scripted parameters is correct. They are evaluated from top to bottom. That means that you cannot reference another scripted parameter that is below in the Navigator tree.
Your list of parameters should therefore have "src" last.
That might be the problem. I will test tomorrow. I cooled down a bit, so I have time to explain clearly.
I used to receive input from the command line:
fme.exe C:\\fme_workbench.fmw --code ny --my_name Nelly --my_status noo ---param x --param2 y --param3 z
(a bunch of params, as you can see)
code, my_name, my_list used to be published params.
The things is, if I know the --code, I will always know which value is my_name and my_status so I would like to spare the user from inputting these params, to somehow compute them inside FME.
I decided to move my_name and my_status to private parameters and to use a python script to return values for these (I followed your example).
Now I have "code" as a published parameter and "src","my_name","my_list" as private parameters.
The cmd line should look like (shorter a bit):
fme.exe C:\\fme_workbench.fmw --code ny ---param x --param2 y --param3 z
Thus, the idea is to find a way to create variables based on a value entered by the user through cmd.exe. I hope that changing their order will fix the issue. If not, I will return with a question.
As David mentioned, the order of parameter definitions is important. If you need to refer to other parameter (e.g. code) from the scripted parameter, the referred parameter should be defined before the script. i.e. upper than the scripted parameter on the Navigator tree. And, maybe you should escape the back slashes, like this. src = 'C:\\\\local\\\\tmp.shp' or use slashes instead. src = 'C:/local/tmp.shp' If you want to create multiple parameters in a script, consider defining a Scripted (Tcl) Parameter. This script example defines two parameters (i.e. macros) named MY_NAME and MY_STATE, and also returns a path string. --- # Scripted (Tcl) Prameter Example set code $FME_MacroValues(code) set index [lsearch -exact {"ab" "ca" "ny"} $code] if {$index < 0} { return "unexpected code" } set name [lindex {"Alex" "Carl" "Nelly"} $index] set state [lindex {"aall" "cast" "noo"} $index] puts "MACRO MY_NAME $name" puts "MACRO MY_STATE $state" return [format {C:\\local\\%s\\%s_%s\\files\\target.shp} $code $name $state] --- Although MY_NAME and MY_STATE will not appear in the parameter list of workbench interface, those can be accessed indeed. e.g. FME_MacroValues['MY_NAME'] in a PythonCaller. As far as I know, Scripted (Tcl) Parameter is the only way to append macros by scripting. Python cannot do it.
The shalshes are escaped, I do not think that is problem.
I took a closer look at the log file and practically it replaced the $my_name and $my_state with everything I have in the scripted parameter, the actual code:
"C:\\code\\my_name\\n<space>=<space>FME_MacroValues<openbraket><apos>..." and so on. Practically, instead of a value, I get the entire code printed.
I took Takashi's advice and replaced the entire workbench with that example. It seems to do everything well, except one thing:
Shape Reader: No shape Files found to process in directory: 'C:\\local\\aa\\Alex_aall\\files\\target.shp"
Now, the printed path is ok, I checked for it, and it is there. I cannot seem to understand why it dosn't open it.
I have a Single Merged Feature type Readed -> Merge Feature Type checked, merge filter * and filter type - wildcard.
I have linked this feature type to a source dataset (Source Esri shapefile) which is linked to the TCL Private parameter. The latter replaces the values well, so this is a huge step forward.
The only problem now is that it cannot find the shapefile althoug he path is surely correct (it is printed correctly in the log).
We use 3 different kinds of cookies. You can choose which cookies you want to accept. We need basic cookies to make this site work, therefore these are the minimum you can select. Learn more about our cookies.