Hi,
a scripted parameter must return one string value, so you could do something like this:
---
import arcpy, os
mxd = arcpy.mapping.MapDocument(r'CURRENT')
version = 'UNKNOWN VERSION' # Default value
for lyr in arcpy.mapping.ListLayers(mxd):
if lyr.supports("SERVICEPROPERTIES"):
servProp = lyr.serviceProperties
if lyr.serviceProperties["ServiceType"] != "SDE":
version = servProp.get('ServiceType', 'N/A')
else:
version = servProp.get('Version')
del mxd
return version
---
Remember that you'll have to use the Python interpreter that has the arcpy module installed, which isn't usually the case for the Python interpreter installed with FME.
Have a look here (
http://fmepedia.safe.com/articles/How_To/Choosing-a-different-Python-Interpreter-installation) for more details about selecting the Python interpreter used by ArcGIS.
David
The script above will return the version for the last layer found in the MXD, which might not always be the best solution, e.g. if the last layer if a WMS base layer or such.
This version will return the first SDE version found and ignore the rest:
---
import arcpy, os
mxd = arcpy.mapping.MapDocument(r'CURRENT')
version = 'UNKNOWN VERSION' # Default value
for lyr in arcpy.mapping.ListLayers(mxd):
if lyr.supports("SERVICEPROPERTIES"):
servProp = lyr.serviceProperties
if lyr.serviceProperties["ServiceType"] == "SDE":
return servProp.get('Version')
del mxd
return version
---
David
@David R.
I'm using the code from your seond post which works great! Thank you!
The issue I have now is with:
mxd = arcpy.mapping.MapDocument(r'CURRENT')
I have my workbench saved as an FME ETL Tool in a ArcToolbox which I've added as a tool to the ArcMap toolbar for the end user to use. This works great but i get an error when running the tool with the map document proptery in Python is set to CURRENT. The error I get is:
RuntimeError: Object: CreateObject cannot open map document
This makes sense since FME doesn't know that I have a MXD open. Is there a solution for this? The workaround I can think of is to hardcode the map document path (not ideal) but the real kicker is that the MXD has to be saved prior to running FME. If I don't save before I run the workbench, it writes to whatever version it was connected to at the last save.
Hi,
not too surprised about that error. I recommend you create a published parameter called "CURRENT_MXD_DOCUMENT", which you can then reference in your script:
mxd = arcpy.mapping.MapDocument(FME_MacroValues['CURRENT_MXD_DOCUMENT'])
You will need to use the full path to the MXD file in the published parameter.
And yes, you will have to save the MXD first, I don't think there's any way around that...
David
@David R.
Is there a way to only look in a specific feature dataset for version names? I'm seeing situations where there are feature classes from multiple feature datasets in an MXD and I'm only concerned about one particular feature dataset (i.e. P_Electric_Distribution that contains 21 feature classes I need to write to).