So here's the situation - a user has a MXD document open connected to an ArcSDE database with a version. I have a workbench to write to this database but the user doesn't want to manually type in the ArcSDE version name as a user parameter (how it's currently setup). Instead they want what ever version they are current connected to in the MXD to be used in the workbench.
I've scraped together some Python code I've found to create a text file of the current version name for an open MXD but I'd like to use this value (or maybe instead the returned value) as a new private parameter to use in the workbench.
Two issues right now:
- It lists the version name for all layers (I just want one record)
- It writes to a text file
- Should it just return the version name so FME can use it as a parameter? If so, how do I do this?
import arcpy, os mxd = arcpy.mapping.MapDocument(r'CURRENT') text_file = open("C:\\temp\\FME_Testing\\Temp\\Test3.txt","w") for lyr in arcpy.mapping.ListLayers(mxd): if lyr.supports("SERVICEPROPERTIES"): servProp = lyr.serviceProperties if lyr.serviceProperties["ServiceType"] != "SDE": print "Service Type: " + servProp.get('ServiceType', 'N/A') else: text_file.write (servProp.get('Version')) text_file.close() del mxd