AnsweredAssumed Answered

arcpy.ChangeVersion_management

Question asked by mhs@mast.dk on Oct 23, 2018
Latest reply on Dec 14, 2018 by mhs@mast.dk

Quick question:

When I execute the lines in the python script below from the Python console within ArcGIS Pro (2.1) I am getting the expected result (the current layer is "changed" to the Version). Please refer to the screenshot ChangeVersion_management.jpg where two database connections (one of them being the SDE.DEFAULT and the other one the versioned one containing the changed layer) are shown.

 

BUT when I try to do the same by executing the script "as a tool" nothing seems to happen and the layer is NOT "changed" to the Version :-(

 

import arcpy
import os

def getcurrentuser():
username = os.environ.get("USERNAME")
username = username.upper()
return username

 

# Set local variables
arcpy.env.workspace = r"C:\geodat1p.sde"
parentVersion = "SDE.DEFAULT"
versionName = sys.argv[1]
fullversionName = 'OPS$'+getcurrentuser()+'.'+versionName

 

# Execute CreateVersion
arcpy.CreateVersion_management(arcpy.env.workspace, parentVersion, versionName, "PUBLIC")
arcpy.AddMessage("Version: {0} created".format(fullversionName))

 

# Changes version on JackupSpud (the layer has already been added to the Map Content-menu/pane)
arcpy.ChangeVersion_management("Jack-up Spud",'TRANSACTIONAL', fullversionName,'')

 

What part of the picture am I not seeing?  :-) Do I need to create a new database connection referencing the Version.

 

I've tried to find a workaround by using the standard Change Version geoprocessing tool but running this on the particular layer referencing the new Version unfortunately doesn't seem to affect it either.

 

I was thinking that perhaps the "List by Data Sources" wasn't automaticly getting updated when executing the function from "outside" the environment but it doesn't help to switch back and forth between the tabs and when I afterwards append data into the layer it unfortunately ends up directly in the SDE.DEFAULT-connection and not in my version-connection where I would like it to go.

 

Kind regards,

Martin

Attachments

Outcomes