1

How can I read a version within Python?

For example, let's say I set up a workspace which points to a .SDE file connection. Now how can I read the features from a version within Python? I have looked online but can't find anything. Ideally if there is a code that looks for the version that is currently active and in use within the mxd?

  • This is an old question here but it sure would be helpful to my current project to be able to determine which version is in use for a feature class within a project automatically with arcpy which none of the solutions here appear to be able to do. Perhaps it can't be done? I'm still looking. I will need to access a saved state of a specific version from outside of ArcMap because the one inside will have a selection. I won't always know which version that is at the time. – jbchurchill Aug 28 '19 at 17:12
3
arcpy.env.workspace = r'Database Connections\adminCon.sde'
arcpy.MakeFeatureLayer_management(r'Database Connections\adminCon.sde\GISADMIN.Buildings', 'fl')
arcpy.ChangeVersion_management('fl', "TRANSACTIONAL", "GISADMIN.Oli")
arcpy.ChangeVersion_management('fl', "TRANSACTIONAL", "sde.DEFAULT")

For further information check:

How to get a search cursor on a particular version in arcpy

1

You can create multiple .SDE file connections, each pointing to different versions.

enter image description here

Then you can refer to the various versions in your code:

arcpy.MakeFeatureLayer_management(r'Database Connections\readonlyCon.sde\GISADMIN.Buildings', 'Buildings_readonly')
arcpy.MakeFeatureLayer_management(r'Database Connections\editorCon.sde\GISADMIN.Parcels', 'Parcels_editable')
0

You can access the version manager via ArcMap or ArcCatalogue and note the versions available or create your own from those available. You can then access it with this code in your script

version = 'SDE.version_name'

for example 'SDE.DEFAULT'. I am new to python scripting in ArcGIS but i guess you can be able to access the features in the ArcSDE geodatabase after setting the version as shown. See this thread on how to define workspace for SDE connections.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.