Solved! Go to Solution.
import arcpy mxd = arcpy.mapping.MapDocument('>>MXDPATHHERE<<') df = arcpy.mapping.ListDataFrames(mxd) #Create list of layer from first dataframe symbologyList = arcpy.mapping.ListLayers(mxd,"",df[0]) layerList = list() #Remove first dataframe from list df.remove(df[0]) #Add the rest of the layers to a list for d in df: layerList.extend(arcpy.mapping.ListLayers(mxd,"",d)) #Compare the layers. If they are the same feature change the symbology. for symbologyLayer in symbologyList: for layer in layerList: if symbologyLayer.dataSource == layer.dataSource: arcpy.ApplySymbologyFromLayer_management(layer, symbologyLayer) mxd.save() del mxd
import arcpy mxd = arcpy.mapping.MapDocument('CURRENT') df = arcpy.mapping.ListDataFrames(mxd) #Create list of layer from first dataframe symbologyList = arcpy.mapping.ListLayers(mxd,"",df[0]) layerList = list() #Remove first dataframe from list df.remove(df[0]) #Add the rest of the layers to a list for d in df: layerList.extend(arcpy.mapping.ListLayers(mxd,"",d) #Compare the layers. If they are the same feature change the symbology. for symbologyLayer in symbologyList: for layer in layerList: if symbologyLayer.dataSource == layer.dataSource: arcpy.ApplySymbologyFromLayer_management(layer, symbologyLayer)
File "C:\Users\greg\Desktop\Clone_symbology_data_frames.py", line 19, in <module> if symbologyLayer.dataSource == layer.dataSource: File "C:\Program Files (x86)\ArcGIS\Desktop10.0\arcpy\arcpy\arcobjects\_base.py", line 70, in _get return convertArcObjectToPythonObject(getattr(self._arc_object, attr_name)) AttributeError: LayerObject: Get attribute dataSource does not exist
import arcpy mxd = arcpy.mapping.MapDocument('>>MXDPATHHERE<<') df = arcpy.mapping.ListDataFrames(mxd) #Create list of layer from first dataframe symbologyList = arcpy.mapping.ListLayers(mxd,"",df[0]) layerList = list() #Remove first dataframe from list df.remove(df[0]) #Add the rest of the layers to a list for d in df: layerList.extend(arcpy.mapping.ListLayers(mxd,"",d)) #Compare the layers. If they are the same feature change the symbology. for symbologyLayer in symbologyList: for layer in layerList: if symbologyLayer.dataSource == layer.dataSource: arcpy.ApplySymbologyFromLayer_management(layer, symbologyLayer) mxd.save() del mxd
import arcpy mxd = arcpy.mapping.MapDocument(r'F:\Muzyl\GIS\Old Data\Michigan LP\MXD\Michigan.mxd') df = arcpy.mapping.ListDataFrames(mxd) #Create list of layer from first dataframe symbologyList = arcpy.mapping.ListLayers(mxd,"",df[0]) layerList = list() #Remove first dataframe from list df.remove(df[0]) #Add the rest of the layers to a list for d in df: layerList.extend(arcpy.mapping.ListLayers(mxd,"",d)) #Compare the layers. If they are the same feature change the symbology. for symbologyLayer in symbologyList: for layer in layerList: if symbologyLayer.dataSource == layer.dataSource: arcpy.ApplySymbologyFromLayer_management(layer, symbologyLayer)
Traceback (most recent call last): File "C:\Python26\ArcGIS10.0\Lib\site-packages\pythonwin\pywin\framework\scriptutils.py", line 309, in RunScript debugger.run(codeObject, __main__.__dict__, start_stepping=0) File "C:\Python26\ArcGIS10.0\Lib\site-packages\pythonwin\pywin\debugger\__init__.py", line 60, in run _GetCurrentDebugger().run(cmd, globals,locals, start_stepping) File "C:\Python26\ArcGIS10.0\Lib\site-packages\pythonwin\pywin\debugger\debugger.py", line 624, in run exec cmd in globals, locals File "C:\Users\greg\Desktop\Clone_symbology_data_frames.py", line 19, in <module> if symbologyLayer.dataSource == layer.dataSource: File "C:\Program Files (x86)\ArcGIS\Desktop10.0\arcpy\arcpy\arcobjects\_base.py", line 70, in _get return convertArcObjectToPythonObject(getattr(self._arc_object, attr_name)) AttributeError: LayerObject: Get attribute dataSource does not exist >>>
Runtime error <class 'arcgisscripting.ExecuteError'>: ERROR 000967: The input layer type must be a feature layer, raster layer, or tin layer. ERROR 000840: The value is not a Layer.
>>> symbologyLayer.isFeatureLayer True >>> layer.isFeatureLayer True >>> for lyr in layerList: ... if lyr.isFeatureLayer: ... print "TRUE" ... TRUE TRUE TRUE TRUE TRUE >>> for lyr in symbologyList: ... if lyr.isFeatureLayer: ... print "TRUE" ... TRUE TRUE TRUE TRUE TRUE