Thanks,
Aaron
Albuquerque, NM
Thanks,
Aaron
Albuquerque, NM
Best answer by takashi
as David mentioned, dynamic prompting is not so easy, but it's not impossible.
One possible way is to create an FME Standard Parameters Dialog with Python script.
If you read schemas with a Schema (Any Format) reader, for example, a PythonCaller with this script shows a dialog box for selecting a feature type name, and outputs a feature having the selected name as an attribute named "feature_type_name".
-----
# Python script example
import fmeobjects, os, tempfile
import winsound # Windows only
class FeatureTypeSelector(object):
def __init__(self):
self.names = []
def input(self, feature):
# Collect feature type names from the input feature
# read by a SCHEMA reader.
self.names.append(feature.getAttribute('fme_feature_type_name'))
def close(self):
# If the list is empty, do nothing.
if len(self.names) < 1:
return
# Sort the list so that the name having last date will be the 1st element.
self.names.sort(reverse=True)
# Create FME GUI directives.
gui = 'GUI TITLE Select Feature Type\\n'
gui += 'DEFAULT_VALUE FEATURE_TYPE %s\\n' % self.names[0]
gui += 'GUI CHOICE FEATURE_TYPE %s Feature Type' % '%'.join(self.names)
guiPath = None
try:
# Create a temporary file and save the FME GUI directives.
fd, guiPath = tempfile.mkstemp(dir = '.')
os.write(fd, gui)
os.close(fd)
# *** Windows only ***
# Play a Windows sound before showing the dialog box.
winsound.PlaySound('SystemAsterisk', winsound.SND_ASYNC)
# Create and show a parameter settings dialog box.
# If the user exits the dialog with [OK], output a feature
# having the selected name as attribute called "feature_type_name".
dlg = fmeobjects.FMEDialog()
if dlg.parameterPrompt(guiPath):
f = open(guiPath)
rows = [r.strip() for r in f.readlines()]
f.close()
feature = fmeobjects.FMEFeature()
feature.setAttribute('feature_type_name', rows[1])
self.pyoutput(feature)
except:
logger = fmeobjects.FMELogFile()
logger.logMessageString('Parameter getting failure.', fmeobjects.FME_ERROR)
finally:
# Remove the temporary file.
if guiPath and os.path.exists(guiPath):
os.remove(guiPath)
-----
You can then send the feature to a WorkspaceRunner to run the main workspace.
Don't forget to expose the new attribute name (feature_type_name) in the PythonCaller parameter settings.
See these documentations to learn more about Python API and GUI directives.
http://docs.safe.com/fme/html/FME_Objects_Python_API/index.html
http://docs.safe.com/fme/html/FME_GuiType/index.html
Takashi
Enter your E-mail address. We'll send you an e-mail with instructions to reset your password.