ListVersions

735
12
06-16-2010 05:52 PM
TedCronin
MVP Honored Contributor
So, is it possible to use ListVersions to list out all the versions as part of a list, have some versions removed from the list, and then proceed to process the list for say a ReconcileVersion_management.  It seems like this should work.

import arcpy

versionList = arcpy.ListVersions ('Database Connections\zzzyyyxxx_tcronin@sdemapper@ACR-GIS2@TestServer.sde')


versionList.remove ('dbo.DEFAULT')
versionList.remove ('ACR_FINAL.Master')

for version in versionList:
    print version



Printed Shows me:

AVATCHAR.NopeTest
MIHILLIG.Shared_AOI_Michael
ACR_GIS.bk111_Jesusa
ACR_GIS.bk222_Jesusa

If i then un comment reconcile above and then run:


RuntimeError: ERROR 087494: Object: Error in executing tool
File "C:\Documents and Settings\tcronin\Desktop\BatchVersionReconcile.py", line 11, in <module>
  arcpy.ReconcileVersion_management (versionList, version, 'ACR_FINAL.Master', "BY_OBJECT", "FAVOR_TARGET_VERSION", "NO_LOCK_AQUIRED", "NO_ABORT", "NO_POST")
File "C:\Program Files (x86)\ArcGIS\Desktop10.0\arcpy\arcpy\management.py", line 9000, in ReconcileVersion
  raise e


If I manually run this tool, I can not see all the versions I want to reconcile, it seems like it is sde connection version specific, but a ListVersion does show me everything, so why is that the case.  Or should I be running this directly in ArcMap, instead of wing.

Wow, Management.py has 9221 lines of code, thats a lot of writing.;)
0 Kudos
12 Replies
RussellBrennan
Esri Contributor
Hi Ted,

ListVersions should return only what that user has permissions to see. Make sure that you are connecting to the same workspace both when running ListVersions as well as when running reconcile. Try setting the workspace environment at the start of your script.

import arcpy
arcpy.env.workspace = r"Database  Connections\zzzyyyxxx_tcronin@sdemapper@ACR-GIS2@TestServer.sde"
...
I did not see in your script where you referenced reconcile. However in the error message the syntax looks incorrect.

arcpy.ReconcileVersion_management (versionList, version,  'ACR_FINAL.Master', "BY_OBJECT", "FAVOR_TARGET_VERSION",  "NO_LOCK_AQUIRED", "NO_ABORT", "NO_POST")

From what I am seeing above you are passing in your versionList where you should be providing a workspace. If you want to run the reconcile for each version you will need to do something like this:

import arcpy
arcpy.env.workspace = r"Database  Connections\zzzyyyxxx_tcronin@sdemapper@ACR-GIS2@TestServer.sde"
workspace = arcpy.env.workspace
versionList = arcpy.ListVersions ()

versionList.remove('dbo.DEFAULT')
versionList.remove('ACR_FINAL.Master')

for version in versionList:
    arcpy.ReconcileVersion_management (workspace, version,  'ACR_FINAL.Master', "BY_OBJECT", "FAVOR_TARGET_VERSION",  "NO_LOCK_AQUIRED", "NO_ABORT", "NO_POST") 
#this is assuming that 'ACR_FINAL.Master is the parent version to all other versions in the list.
0 Kudos
TedCronin
MVP Honored Contributor
I will test this out.  I agree I did not attach the reconcile piece.  I totally left off the workspace, for whatever reason, perhaps I thought I could jump right in.  Maybe this was a total brain fart.


Running this:

import arcpy

arcpy.env.workspace = r"Database Connections\zzzyyyxxx_tcronin@sdemapper@ACR-GIS2@TestServer.sde"

wrksp = arcpy.env.workspace

versionList = arcpy.ListVersions ()


versionList.remove ('dbo.DEFAULT')
versionList.remove ('ACR_FINAL.Master')

for version in versionList:
    print version
    #arcpy.ReconcileVersion_management (wrksp, version, 'ACR_FINAL.Master', "BY_OBJECT", "FAVOR_TARGET_VERSION", "NO_LOCK_AQUIRED", "NO_ABORT", "NO_POST")
    #print version


I am receiving a windows error, so I will play with this a bit more
0 Kudos
TedCronin
MVP Honored Contributor
So, I am trying to run this as a script outside of ArcMap and Editing, so is that even possible, because the more I think, the more I come to realize that when doing reconciles I am in ArcMap and have started editing and not on the outside of both, so it seems like I should be creating a map connection and running a start edit, and then running the reconcile.
0 Kudos
RussellBrennan
Esri Contributor
Ted,

You can run the reconcile outside of an edit session and outside of ArcMap/ArcCatalog. The edit session will taken care of by the tool. Just be sure to choose the appropriate conflict detection method and reconcile option (favor target or favor edit) because the reconcile will be saved when the tool finishes.
0 Kudos
TedCronin
MVP Honored Contributor
This is good to know because I am seeing inconsistent behavior between No Post, and No Locks in py and the doc as well as when a model is exported out with either of these optional check boxes but will revisit next week as I try and ascertain the exact behavior.  BTW, the doc does make it seem like I need to be in an edit session.
0 Kudos
RussellBrennan
Esri Contributor
  BTW, the doc does make it seem like I need to be in an edit session.


Ted,

Are you referring to this line?
"The reconcile process requires that you are the only user currently   editing the version and the only user able to edit the version   throughout the reconcile process until you save or post."

In this doc:
http://help.arcgis.com/en/arcgisdesktop/10.0/help/index.html#//0017000000p9000000.htm
0 Kudos
TedCronin
MVP Honored Contributor
Yep, that first part makes you think you need to be editing, at least it made me think that way.
0 Kudos
TedCronin
MVP Honored Contributor
So basically this runs as expected, in the python window, but for some reason, I do not have list.remove in Wing.  This is the issue I am having.
0 Kudos
TedCronin
MVP Honored Contributor
I am having issues with both IDLE and PyWin, too.  The only thing I can come up with is I did not choose the default setup, since I do not want py to be uninstalled by ArcGIS, so basically three IDEs don't work, and 1 does (py window).
0 Kudos