I use scripted parameters from a configuration-file, similar to explained in many blog-posts.
Te location of the script is passed through a public parameter of the type 'file(existing)'.
This parameter sometimes contains an absolute path, when the config-file is stored somewhere on the filesystem, but sometimes part of it is a FME parameter such as $(FME_MF_DIR) when the config-file is stored close to the workspace. Also, on server, I deliberately use a server-parameter such as $(FME_SHAREDRESOURCE_DATA).
To cope with this, I have had to hack a quite nasty looking bit of python
import fme import ConfigParser import os import re fmeParam = re.compile("A$(FME_[A-Z]+_[A-Z]+)") fmeParamName = re.compile("FME_[A-Z]+_[A-Z]+") def findAbsolutePath(fileParamName): paramValue = fme.macroValues[fileParamName] fmeParamList = fmeParam.findall(paramValue) if fmeParamList != []: fmeParamKey = fmeParamName.findall(fmeParamList[0])[0] fmeBasePath = fme.macroValues[fmeParamKey] relFilePath = fmeParam.split(paramValue)[1] absFilePath = os.path.join(fmeBasePath,relFilePath) else: absFilePath = paramValue return absFilePath filePath = findAbsolutePath("conffile") conf = ConfigParser.ConfigParser() conf.optionxform = lambda option: option conf.read(filePath) return conf.getint("Parameters","MyBeautifulNumber")
testing for the presence of FME-parameters, filtering out the key I need to get them from macroValues, and glueing it all together for an absolute path where I can find my config-file.
Could there be a function like fme.getAbsolutePath('[key_of_filepath-parameter]')?
Kind regards,
Martin