Skip to main content

Hi

I have an FME process that uses as its inputs a GDB file and its associated XML schema file. I want to generate the XML from the GDB at runtime, and I have a python startup script to do this in ESRI - this works. My issue is with populating the parameter for the XML reader to set the location (for the generated file). I've read through some of the articles and previous questions, and this one seems to be what I'm looking for, although given I'm not python literate/new to it, I wasn't able to make the solution work for me - apologies for the ignorance.


https://knowledge.safe.com/questions/4296/set-published-parameters-in-a-python-startup-scrip.html

I think I need to add 'import fmeobjects' and 'return ResultsXML' added to my current script (below), but when I do so I get an error about return statement being outside a function. I don't know how to place it inside a function,.. help please.

Assuming that works, how do I expose it within FME? I was thinking a published parameter that I can then use in the Reader or pass to a FeatureReader?

My workaround at the moment is to recalculate the ResultsXML/XML location from the GDB location, but would be neater to have it work from the startup script.

Any help, much appreciated

Thanks

Mary

In my test scenario:

FMEProcess.FMW

/data - this contains the GDB source file, although this file could be sourced from anywhere

/input - where I output the XML file from python/ESRI

/output - where I output the FME process

The startup python script:

import os

 

import sys

 

sys.path.append("C:\\\\Python27\\\\ArcGIS10.4\\\\Lib\\\\site-packages")

 

sys.path.append(r'C:\\Program Files (x86)\\ArcGIS\\Desktop10.4\\arcpy')

 

sys.path.append(r'C:\\Program Files (x86)\\ArcGIS\\Desktop10.4\\ArcToolbox\\Scripts')

 

sys.path.append(r'C:\\Program Files (x86)\\ArcGIS\\Desktop10.4\\bin')

 

sys.path.append("C:\\\\Python27\\\\ArcGIS10.4\\\\Lib")

 

import arcpy

 

import fme

 

import re

# from fme.macroValues

 

path = fme.macroValuesa'FME_MF_DIR']

 

dir1 = fme.macroValuesm'SOURCE_GDB']

 

# current path = C:\\temp\\

 

# current dir1 = C:\\temp/data/TEST.gdb

 

# desired dir2 = C:\\temp\\input\\TEST.xml

# grab gdb file name assign to fname var

 

newpath = dir1.split("\\\\")

 

fname = newpath>-1].replace(".gdb",".xml")
# construct desired xml path

 

dir2 = path + "input/" + fname

# generate xml via ArcGIS

 

MyGDB = dir1

 

ResultXML = dir2

 

print("processing %s" % MyGDB)

 

## delete only if file exists ##

 

if os.path.exists(ResultXML):

 

os.remove(ResultXML)

 

else:

 

print("cannot remove existing file %s." % ResultXML)

 

arcpy.ExportXMLWorkspaceDocument_management (MyGDB, ResultXML, "SCHEMA_ONLY", "BINARY", "METADATA")

If you change your startup script to a private scripted parameter, and add the line return ResultXML at the end.

 

The parameter value will be the path to the xml and can be used directly by the xml reader.

Thanks jdh, I found the private scripted parameter - thank you.

I'm now getting a python error message, but at least can work with that now.

Thank you

Mary


Hi @marwee, another approach, if you use a FeatureReader transformer to read the XML, you can execute the script with a PythonCreator to create a feature having the XML file path as an attribute and then set the attribute to the Dataset field in the FeatureReader.


Reply