0 Replies Latest reply on Sep 26, 2011 6:57 AM by flederfauz

    UpdateLayer Problems with Layers that use Representations and Annotations

      I wrote some code that updates Layer properties in a map with source Layers in a folder.  The first thing I discovered that arcpy.mapping.UpdateLayer can not process input from Layers whose path includes a Folder with numbers only (in my case *\2011\*). When I finally discovered I changed the name and it was ok.
      But; when the Script runs over a Layer using Representations or an Annotation I get the following message: LayerObject: Get attribute renderer does not exist.
      Am I right assuming that I can not access those objects? If so how can I sort them out? And how can I update them with antother method?

      Thanks a lot

      here my code

      import arcpy
      from arcpy import env
      import os
      #Set the mxd to the currently opened map
      mxd = arcpy.mapping.MapDocument("CURRENT")
      #Get workspace where the master Layers which layout and properties you want to
      #copy are stored e.g. C:/SourceLayers "P:/RAME/GIS/Layers"
      env.workspace="P:/RAME/GIS/Layers" #arcpy.GetParameterAsText(0)
      #Decide if All Properties or only Symbology is updated. Default is FALSE
      #Create a List for each layer in your Source Folder containing Name and Path
      for file in arcpy.ListFiles("*.lyr"):
         name = os.path.splitext(file)[0] + ".lyr"
         head, sep, tail = name.partition('.lyr')
         tempList=[[name, path]]
      # loop through layers to get layer names and replace layer file
      dfs = arcpy.mapping.ListDataFrames(mxd,"*")
      for mxdLayer in arcpy.mapping.ListLayers(mxd,"",""):
         temp2= str(mxdLayer.name) 
      x = mxdlyr
      y = fcList
      #find the source layers that exist in the mxd
      def find_match(x, y):
         match = []
         for i in x:
            for j in y:
               if i == j[0]:
         return match
      match = find_match(x, y) # create a generator
      #Loop through all Dataframes
      for df in dfs:
         #Loop through all Layers of the match list(source layers that exist in the mxd)
         for fc in match:
            #get the name of the layer out of the list
            print tempname
            #get thesource path of the layer out of the list
            print tempname2
            #Prepare the variables used in the UpdateLayer Command
            df = arcpy.mapping.ListDataFrames(mxd, dfName)[0]
            updateLayer = arcpy.mapping.ListLayers(mxd, tempname, df)
            print updateLayer
            sourceLayer = arcpy.mapping.Layer(tempname2)
            print sourceLayer
            #Steps through all Layers in the mxd with the same Name and updates them
            for lyrs in updateLayer:
               updateLayer = arcpy.mapping.ListLayers(mxd, tempname, df) [x]
               x =x+1
               arcpy.mapping.UpdateLayer(df, updateLayer, sourceLayer, SymbologyOnly)
      # refresh view and table of contents, save changes to mxd         
      #Tidy up
      del sourceLayer, mxd