5

I'm trying to write a script to change the label next to the symbol in the TOC so it appears in the legend. ArcPy has a way to change the name of the layer, but I can't seem to find a way to change the text one level below that. They also have a way to change unique symbol texts and descriptions, but that's not what I need either. Am I just missing it in the tutorials/help pages?

It's just the text box in the layer's Properties under the Symbology tab. There's a box that says "Legend" and then "Label appearing next to the symbol in table of contents."

closed as off-topic by PolyGeo Aug 4 '16 at 21:41

This question appears to be off-topic. The users who voted to close gave this specific reason:

  • "Questions seeking help to debug/write/improve code must include the desired behavior, a specific problem or error and the shortest code necessary to reproduce it in the question itself. Providing a clear problem statement and evidence of a code attempt will help others to help you. See: How to create a Minimal, Complete, and Verifiable example." – PolyGeo
If this question can be reworded to fit the rules in the help center, please edit the question.

1

You are on the right track with looking in arcpy. You simply need to look at the arcpy.mapping module. The amount of flexibility you have here will depend on what version of ArcGIS you are using. There were some pretty significant additions made at 10.1 that added a lot of functionality. One of these additions were a set of modifiers for different symbology types.

Here is the initial help for arcpy.mapping: ArcGIS Help 10.1 - Introduction to arcpy.mapping

This screenshot of the arcpy.mapping classes shows the different symbology types you are able to access and modify programmatically: arpy.mapping classes

Here is the help for the unique values symbology: ArcGIS Help 10.1 - UniqueValuesSymbology (arcpy.mapping)

Definitely take a look at these help documents and always look down at the end of each one. That is where they have code samples, which are extremely useful!

One important note, and I quote:

Basic operations such as modifying class values and labels, or changing the field that the symbology is based on are some of the properties that can be modified. For access to the complete set of layer symbology properties and settings, for example, changing individual symbols for individual classes, it is necessary to author these changes in the ArcMap user interface and then save those changes to a layer file. These custom settings can then be applied to existing layers using the UpdateLayer function.

Essentially, know that while you will be able to access an increasing number of properties through here, sometimes you will just have to set something up by hand, save it, then apply that saved layer file to existing layers to get the look that you want.

1

Not sure if it fits with your workflow at all, but it may be worth creating a few pre-authored .lyr files and using ApplySymbologyFromLayer on the TOC layer that you'd like to change. It would work if you only have a few preset label sets you're hoping to apply, but not if it'll be different every time.

0

You are asking about symbologyType OTHER (not UNIQUE) which you cannot access from ArcPy.

That addresses your question, because I know exactly what you are asking about and I've tried everything to get at it myself, ending in failure.

I don't know if there is another way to convert a layer from symbologyType OTHER to symbologyType UNIQUE in arcpy. I have a suspicion there isn't (it is read-only). But once a layer is symbologyType UNIQUE, you can access it's labels through symbology.classLabels. I use this regularly in automation code and to make multi-line labels (rather than rely on word wrap).

  • 1
    Does this geonet thread provide a possible solution even as a workaround? I don't know enough about the topic to tell. – mkennedy Apr 28 '15 at 20:00
  • It does. Add a field in which every entry is the value you want for the label, then you can select it in the unique value category and then access it in arcpy as symbologyType UNIQUE. A bit of a stretch... – AndrewBenjamin Apr 28 '15 at 20:05
  • 1
    Thank you for making some changes and toning things down. But insofar as the downvoting goes, the mouseover text next to the downvote button merely states "This answer is not useful." Whether or not this post is correct, it's not hard to see why people would consider it to be somewhat less than constructive, even in its modified form. The information in the preceding comments, though, looks like it could be useful. Although I can't predict how people vote, I would expect to see more upvotes if that information were incorporated in the answer itself. (cc @mkennedy) – whuber Apr 28 '15 at 20:22
  • 1
    @whuber The answer is meant to save people time. In that sense, it is useful. I apologize for my tone, but I've spent a long time in ArcGIS Help. – AndrewBenjamin Apr 28 '15 at 20:28
  • 1
    Believe me, I understand your frustration. But tempting though it may be to vent it, this is not the right place. If you truly wish to save people time, consider demonstrating--with examples and references if possible--exactly why reading the help pages will not be of assistance and then describe a workaround. My experience has been that people usually appreciate such advice and they continue to do so for many years. – whuber Apr 28 '15 at 20:35

Not the answer you're looking for? Browse other questions tagged or ask your own question.