Select to view content in your preferred language

Managing Symbology using Python

24028
25
11-23-2011 05:15 AM
DaveJordan1
Regular Contributor
Can someone point me to the correct help source for managing symbology using python?  I want to change symbol colors, line widths... for feature classes as well as graphics

Thanks in advance
Tags (2)
25 Replies
DaveJordan1
Regular Contributor
I found this sample code for UdateLayer (using a .lyr file).  However, I used a No Color option in the .lyr file  but it comes in solid Black!!!:


import arcpy

#Reference layer in secondary map document
mxd2 = arcpy.mapping.MapDocument(r"C:\Project\ProjectTemplate.mxd")
df2 = arcpy.mapping.ListDataFrames(mxd2, "Layers")[0]
sourceLayer = arcpy.mapping.ListLayers(mxd2, "Rivers Group Layer", df2)[0]

#Update layer in primary map document
mxd = arcpy.mapping.MapDocument(r"C:\Project\Project.mxd")
df = arcpy.mapping.ListDataFrames(mxd, "County Maps")[0]
updateLayer = arcpy.mapping.ListLayers(mxd, "Rivers", df)[0]
arcpy.mapping.UpdateLayer(df, updateLayer, sourceLayer, False)

#Save to a new map document and clear variable references
mxd.saveACopy(r"C:\Project\Project2.mxd")
del mxd, mxd2
0 Kudos
JasonHarshman
Frequent Contributor
I'm having the exact same problem. If the original polygon symbology is hallowed or outlined, then the script will fill the polygon with black. However, if I open or import the layer file within ArcMap the proper symbology is displayed. I haven't tried it with points or polyline features yet.
0 Kudos
DaveJordan1
Regular Contributor
jaybo684 - I still don't have a solution for this issue.  In fact, when I received notification that you had commented on this post, I was looking at  the same issue generated from a Flex widget...
0 Kudos
ThaiTruong
Deactivated User
I just skim through the functions and classes under arcpy site package from the help file, yet could not find any methods to manipulate the symbology either.  The only way I can do this is to apply the symbology to my new feature class from another existing layer using "gp.applysymbologyfromlayer".

Here's the link:
http://help.arcgis.com/en/arcgisdesktop/10.0/help/index.html#//00170000006n000000
JeffBarrette
Esri Regular Contributor
I can not reproduce this.  I've tried updating with layers from layer files, other MXDs (as in your example), I've done with with stand alone scripts, using CURRENT, etc.

Please provide more detailed steps so I can evaluate this further.

Thanks,
Jeff
0 Kudos
WilliamIde
Emerging Contributor
All I want to do is to change the size and color of the points in a layer file.  Easy to do in Arcmap.  Impossible in arcpy?
Shouldn't be.
0 Kudos
GIS1
by
Emerging Contributor
Hi Ubanide,

I know what you mean.

Though I do not have a solution and haven't figured out how to do what you want (I wouldn't mind knowing), I can tell you how we do it. We simply make layer .lyr files with the symbology we want already customized and save them to our network drive. Then we just use those in our scripts to apply symbology from them. Might be a workaround for you if you can't figure out how to do it your way.

Best of luck!
0 Kudos
ChristopherThompson
Frequent Contributor
Here is a quote from a presentation from ESRI about map automation using python:
"This is not a replacement for ArcObjects â?? we are trying to draw a line in the sand"
Clearly, the powers that be at ESRI want you to do something as 'advanced' as changing basic symbology (like point sizes and lineweights, colors, etc.) by using ArcObjects. The updateLayer method referencing an existing .lyr maybe your best bet. Just another somewhat annoying thing, like having to create a .lyr file before you can add a layer to a map document.
0 Kudos
JeffBarrette
Esri Regular Contributor
I'm the guilty one, that was my presentation and my quote.  Now I want to give it some context and ask a couple of questions.

Authoring symbology in ArcMap is a simple process but think of all the possibilities and all the options available via the symbology properties dialog.  We could easily triple the arcpy.mapping API but just attempting to provide all that capability.  We don't want to do that.  We are trying to keep arcpy.mapping as simple as possible without making it as complex as ArcObjects.  Do you just want to change the color ( should we include RGB, CMYK options), or will you also want to change the symbol size, outline width, pattern, etc, etc?  That was the point of attempting to draw the line in the sand between what is pure map automation and what can be done with ArcObjects.

Help me understand, in a real mapping scenario, why do you need to dynamically change these symbol properties?  Why does the color/size of a layer need to change going from map sheet to map sheet?  If the point is to update the color for a layer in many map documents across a system, then UpdateLayer along with a layer file works really well (without having to recreate ArcObjects capabilities at the arcpy.mapping level).

I'm not trying to argue here, I'm looking for well documented scenarios to help us continue expanding the capabilities of arcpy.mapping where absolutely needed for map automation tasks.  At 10.1, we added quite a few new capabilities including some symbology classes that are needed to support map automation: GraduatedColorSymbology, GraduatedSymbolsSymbology, etc.

Thanks for your help,
Jeff