Tuesday, 21 July 2015

arcgis 10.0 - Change Symbology of layers from within ArcMap


In an active ArcMap session - I want to change the symbology of a layer which is repeated multiple times in the mxd. Can I do this?


The basic code I have for getting the layers is below. This is running within ArcMap (not as a .py script)



myMXD = arcpy.mapping.MapDocument("Current")
lstDataFrames=arcpy.mapping.ListDataFrames(myMXD)
lstLayers=arcpy.mapping.ListLayers(myMXD)

hazardLayer=arcpy.mapping.ListLayers(myMXD,'*Haz*')

allFrames=arcpy.mapping.ListDataFrames(myMXD)

for dataFrame in allFrames:
myMXD.activeView=dataFrame

for mapLayer in hazardLayer:
mapLayer.visible=False

This just changes the visibility to off...can I change the color for example to some RGB value?



Answer



First create a default layer file to use as a template then:


myMXD = arcpy.mapping.MapDocument("Current")
lstDataFrames=arcpy.mapping.ListDataFrames(myMXD)
lstLayers=arcpy.mapping.ListLayers(myMXD)


hazardLayer=arcpy.mapping.ListLayers(myMXD,'*Haz*')

allFrames=arcpy.mapping.ListDataFrames(myMXD)

for dataFrame in allFrames:
myMXD.activeView=dataFrame
for mapLayer in hazardLayer:
arcpy.ApplySymbologyFromLayer_management(mapLayer, r"C:\TemplateLayers\HazardTemplate.lyr")

No comments:

Post a Comment

arcpy - Changing output name when exporting data driven pages to JPG?

Is there a way to save the output JPG, changing the output file name to the page name, instead of page number? I mean changing the script fo...