4

I am trying to use arcpy to identify the name of the archive class for a number of feature classes, but cannot find a function that will output the name of the archive class, only whether the feature class has archiving enabled.

import arcpy

gdbConn = r"Database Connections\ScriptTest.sde"
arcpy.env.workspace = gdbConn

queryResult = ["List of all my feature classes"]

for row in queryResult:
    gisLayer = row
    desc = arcpy.Describe(gisLayer)
    if desc.isArchived:
        print "{} has Archiving Enabled".format(gisLayer)

        gisLayer_Archive = "" # Identify Archive Class here

        arcpy.FeatureClassToFeatureClass_conversion(gisLayer_Archive, r'D:\temp\TempOutput.gdb', gisLayer_Archive)

My intention is to take a copy of each archive class and save them in a file geodatabase.

Is there a way to find the name of the archive class for archived feature classes in a geodatabase so that I can copy those archives out?

I could possibly assume that all archive classes have a _H suffix, however it is possible that some of these have changed over time.

ArcGIS for Desktop/Server 10.3.1 MS SQL Server 2012

  • In what cases would an archive name be different from ObjectClassName+"_H"? Genuinely curious. I know you can set up your own naming conventions using the SDK, but are there other situations where it would be different? Would renaming a class affect the archive name? – nwduncan Sep 21 '16 at 3:48
  • 1
    @nwduncan you can rename the archive class in ArcCatalog, but more likely the archive has been disabled then re-enabled which causes it to be _H1 or _H2 – Midavalo Sep 21 '16 at 4:15
5

There is no way to find this out using arcpy functions, however using arcpy.ArcSDESQLExecute lets you submit SQL queries, so you can stay within the Python ecosystem.

import arcpy

fc = 'SIGNPOSTS'
sql = '''select table_name from sde.SDE_table_registry where
registration_id = (select history_regid from sde.SDE_archives where archiving_regid =
(select registration_id from sde.SDE_table_registry where table_name = '{0}'))'''.format(fc)

con = arcpy.ArcSDESQLExecute(server='localhost', instance='sde:sqlserver:localhost',database='gdbname')

print con.execute(sql)

>>> SIGNPOSTS_H

  • Thanks for that. Yes this is pretty much the same as what I ended up with (once I figured out which tables to use). I quite like ArcSDESQLExecute(), I use it often – Midavalo Sep 21 '16 at 6:16
  • No problem at all. Would have answered earlier, but the time zones are out of sync ;) Agree, very handy to be able to submit the queries. Keep in mind that you can also submit other calls - I call often some stored procedures with EXEC and then get back the result as a recordset or a scalar value in Python (provided it was a part of SELECT statement). – Alex Tereshenkov Sep 21 '16 at 6:35

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.