arcpy - how to change data source of an annotation feature class?

2897
0
03-09-2015 07:39 AM
AllenGuan1
New Contributor II

I have a layer file which has a group layer. The group layer has two sub layers, one is a normal SDE feature class, the other is a SDE annotation feature class. My intention is to change the data source of both feature class layers. I have no problem using arcpy to change the data source for the normal feature class, but arcpy treats the annotation class as a group layer, and I am not able to see or change its data source. I am using ArcgIS 10.0. The follow code always gives :"can not describe ... layername" on the annotation layer on desc = arcpy.Describe(lyr).

lyrfile = r"C:\Users\guana\AGS100LayerFiles\Lease_License\Non Nexen Lease - Lexco.lyr"
target_wspace = r"L:\GIS\GIS_Services\sso@usqa06.sde"
# where to save the layer files
savedir = r"C:\Users\guana\AGS100LayerFiles\SSO_QA\Lease_License"

layer = arcpy.mapping.Layer(lyrfile)

for lyr in arcpy.mapping.ListLayers(layer):

    hasDataSource = False

    if not lyr.isGroupLayer:

        print "Normal layer %s" % (lyr.longName)

        if lyr.supports("DATASOURCE"):
            hasDataSource = True
            #print lyr.dataSource
            dest_fname = os.path.join(savedir, lyr.longName)
    else:
        print "%s is a group layer " % (lyr.name)
        dest_fname = os.path.join(savedir, lyr.name)
        # see it is an annotation featuer class
        try:
            desc = arcpy.Describe(lyr)
            if desc.dataElement.dataType == "FeatureClass":
                if (desc.featureType in ["Annotation","CoverageAnnotation"]):
                    print "%s is an annotation layer: dataSource = %s" % (lyr.name, lyr.dataSource)
                    hasDataSource = True

        except:
            print "can not describe " + lyr.name

Running this on the annotation feature class always fails:

lyr.replaceDataSource(target_wspace, 'SDE_WORKSPACE', lyr.datasetName, True)

Any help is greatly  apprciated.

0 Kudos
0 Replies