Possible to change legend description from a script? Python or C#?

1254
4
05-02-2012 06:53 AM
NickFillo
New Contributor III
I have a mxd project where layers will be turned on and off as needed.

When the layers will be turned on, they will have valid times.  Example:
Valid 8:00 PM Monday Sept. 24
Until 6:00 AM Tuesday Sept. 25

As you see, the valid start/end will be on 2 lines, which can only be accomplished through the legend description.  Legend label will only allow text to display on 1 line, which won't work.

A Layer file is no good due to the unlimited number of possibilities for the valid start/end times.

Is there a way in any scripting language (python, C#, etc.) that you can access the legend description and make changes?  If so, could you please provide a example of code?

Thanks very much for any help I can get.
Tags (2)
0 Kudos
4 Replies
JeffBarrette
Esri Regular Contributor
What type of symbology are you using on your layer?  At 10.1 we've added some new symbology options but it depends on the symbology type (e.g., graduated colors, graduated symbols, etc).

Also - where in the UI are you changing the layer item descriptions so that it has more than more line per symbol.  I'm not able to do it in the UI.  I'm trying to do it via layer properties --> symbology tab.  For unique value, I select the individual symbol, right-click and select Edit Description.  It does NOT allow multiple lines.

Jeff
0 Kudos
NickFillo
New Contributor III
Hello Jeff,

For the symbology, I am currently going with "unique values, many fields" because the valid begin and valid end times of my polygons are each a layer attribute.  Since the layer is created through a script I wrote, I could adjust the code to combine the beginning/end times into a single attribute and then change the symbology to "unique values".  So I do have options there.  Each polygon is intended to display as a unique solid color.

My problem then becomes how to make that value into 2 lines in the legend.  We already know we can't make the legend label into 2 lines in 10.0 (and I'm hoping the improvements you mentioned in 10.1 help make this possible in some way or another).  Arcpy does not provide a function that allows the legend descriptions to be edited from a script, but I'm wondering if there's a python guru out there who came up with a backdoor way to do it, or if anyone knows how to do this in C# or any other language.

For your second paragraph, I'm not sure I'm answering correctly, but you can make the item descriptions under layer properties > symbology into multiple lines manually.  To get to the next line in the description box, you have to hit Ctrl-Enter.

Nick
0 Kudos
JeffBarrette
Esri Regular Contributor
Unfortunately, we did not expose Unique Values, many fields at 10.1.  We did expose Unique Values and it is possible to add multiple lines to each description.  The example below modifies the descriptions of 2 unique values.

mxd = arcpy.mapping.MapDocument("current")
lyr = arcpy.mapping.ListLayers(mxd, "my Unique Value Layer")[0]
if lyr.symbologyType == "UNIQUE_VALUES":
  lyrSym = lyr.symbology
  lyrSym.classDescriptions = ["temp1\r\ntemp2", "temp1\r\ntemp2"]


Jeff
0 Kudos
NickFillo
New Contributor III
Jeff,

Thanks again for you help.  The code you provided looks like it should do what I need it to.  Can't wait to test it out after upgrading to 10.1.

Thanks again.

Nick
0 Kudos