Â
Â
Thanks,Â
Â
AaronÂ
Albuquerque, NMÂ
Â
Thanks,Â
Â
AaronÂ
Albuquerque, NMÂ
Â
there is no very simple mechanism for dynamic prompting of parameter values in FME, but you can easily create a list of all the available feature type names using the "Schema (Any Format)" reader on your dataset. You can then send this info into a WorkspaceRunner as the source of "Feature types to read" of a dynamic reader.Â
Â
DavidÂ
Â
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 oOK], 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', rowsa1])Â
               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Â
Â
One tip, change the keyword "CHOICE" to "LISTBOX" on line 25 and you get this very nice way of picking multiple feature types:Â
Â
Â
Â
The attribute "feature_type_name" will now contain a space-delimited list of all the feature types, ready for the "Feature types to read" in the WorkspaceRunner :-)Â
Â
DavidÂ
Although I've never try, possibly the FMEDialog trick is also applicable in a scripted parameter definition of the main workspace with using FMEUniversalReader to read schemas.Â
Â
Thanks for the information! I was able to use a Schema (Any Format) Reader, Takashi's code in a PythonCaller, and a FeatureReader (pushing the features out the Other port) to do what I want. Doing so allowed me to keep everything in one workspace too.Â
Â
I tried the WorkspaceRunner but couldn't figure out how to set up "Feature Types To Read" as a parameter. I should do so in the workspace being called by the WorkspaceRunner, correct? I assume the "Feature Types To Read" parameter should then appear as one of the parameters in the WorkspaceRunner. Is that right? If so, could one of you explain the steps involved?Â
Â
Thanks again,Â
Â
AaronÂ
Â
Â
Right-click > Create User Parameter, save the workspace.Â
Then, the parameter will appear in the WorkspaceRunner which calls the main workspace.Â
Â
AaronIt looks like I spoke too soon. Setting a user parameter for Feature Types to Read works but only if I choose one of the feature types already "hard-coded" in the feature types list of the main workspace. Let me explain. The ESRI file geodatabase I am using currently has 3 feature types in it but that number will grow by one every month. Eventually I will want to choose one of the new feature types (that doesn't currently exist). I can dynamically find all of the feature types in the workspace with the PythonCaller script at runtime. But the script called by the WorkspaceRunner has all the feature types "hard coded" in the feature types list. I can't figure out how to get the reader in that main workspace to see all the feature types at runtime. I've scoured FME Help and the FME User Community and perfomed several Google searches to no avail. There has got to be a way to do this. What am I missing?
Â
Â
Â
Â
Â
Â
I think the issue is my main workspace, the one being called by the WorkspaceRunner. The main workspace doesn't dynamically update its feature types; they are static. Is there a way for the main workspace to get all the feature types in the file geodatabase at runtime? I haven't been able to get that part to work.Â
Â
Â
Â
Â
Â
Â
Aaron