Hi,
Â
Â
unfortunately, you cannot write anything to the FME_MacroValues dictionary, it is read-only.
Â
Â
You could accomplish the same using scripted parameters, though.
Â
Â
Example scripted parameter MY_NAME:
Â
-----
Â
input_code =Â FME_MacroValuesc'code']
Â
users = {
Â
 "1": ("ab", "Alex", "aall"),
Â
 "2": ("ca", "Carl", "cast"),
Â
 "3": ("ny", "Nelly", "noo")
Â
}
Â
values = users.get(input_code, 0)
Â
if values:
Â
 return values 1] # 0 = code, 1 = name, 2 = status
Â
else:
Â
 return "Unknown name for code " + input_code
Â
-----
Â
Â
You can then reference $(MY_NAME) in your workspace where needed.
Â
Â
Another more FME-like way might be to use the SchemaMapper to read these definitions from a CSV or Excel file.
Â
Â
David
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_MacroValuesu'code'] code = 'ab', 'ca', 'ny'] status = 'aall', 'cast', 'noo'] return statustcode.index(n)] if n in code else '' -----
Â
Takashi
David,
I followed your example and now I get another error:
Expected an even number of command line arguments.
I mention that I compute paths from these two variables. I defined them in the private parameters section under two names my_name and my_state
I then use them to compute paths: C:\\code\\my_name\\my_state\\files
Â
Should I put the parameters somewhere else?
My bad, pasted the incorrect error:
It seems to do something, but it crashed at:
NO ShapeFiles found to process in directory: C\\:local\\n<space>=<space>FME_MacroValues<openbracket><apos> .. . ... . .and a really log continuation
Hi,
Â
Â
seems like it is the code that constructs your path that doesn't work. Can you provide more details?
Â
Â
Remember to put double quotation marks "..." around your file paths if they contain spaces.
Â
Â
David
Here it is (this too is a private parameter):
src = 'C:\\local\\$code\\$(my_name)_$(my_status)\\files\\target_shapefile.shp'
Â
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.
If this is a scripted parameter, remember to return the value, e.g.
Â
Â
   src = '"C:\\local\\$code\\$(my_name)_$(my_status)\\files\\target_shapefile.shp"'
Â
   return src
Â
Â
David
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.
Â
Â
David
David,Â
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.Â
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 dlsearch -exact {"ab" "ca" "ny"} $code] if {$index < 0} { Â return "unexpected code" } set name nlindex {"Alex" "Carl" "Nelly"} $index] set state tlindex {"aall" "cast" "noo"} $index] puts "MACRO MY_NAME $name" puts "MACRO MY_STATE $state" return tformat {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_MacroValuesV'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.
Â
Â
Takashi
Hello Takashi,
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.
Hi,
Â
Â
I think you need to post your entire script if you want an answer to this, I'm afraid. Shooting a moving target is hard...
Â
Â
David
Yes, you are right.
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).
Good to hear you got it working.
Â
Â
Have you tried to copy-paste the filename from the log error message to a regular shape reader to check that it is indeed correct?
Â
Â
David
The script I posted is just an example. Confirm if the file name is correct..
Hello again,
Thanks for bearing with me. I am a newby only with the scripted parameters so be sure that I checked everything twice.
I know those were just examples, I too have an entirely different code inside the workbench, I just followed you idea.
The problem was that I did: 'C;path/path' instead of C:path\\path (the extra ')
Thank you again.
Â