Use Arcpy to manipulate Representation Legend Properties

2328
1
05-28-2014 01:21 PM
MattGray
New Contributor
I have a Unique Values layer file (.lyr) that has a couple dozen unique value symbols in it.  I have been working for a while to get a python script tool to apply this symbology to an ouput from the script tool, and then put it into an active MXD.  Then when it is put in the MXD,  I want to be able to remove some of the symbols in the Table of Contents, while retaining all the symbology in the Dataframe.  After a week of searching, I found Representations have the ability to give me this functionality, using the Legend Options menu in the Symbology tab for that Representation, pictured below.

[ATTACH=CONFIG]34144[/ATTACH]

Plus I found out that Representations have Arcpy functionality to create and add them to layers and such, but there is absolutely no way I can find to replicate in Arcpy the functionality the Legend Options menu gives you.  This is the very last aspect of a tool I am working on at work, and this is driving me crazy.  Why does ESRI not provide Arcpy functionality to manipulate every single menu option you can do in the Arcmap GUI, even the small, insignificant ones like the Legend Options on the Representation properties menu?
Tags (2)
0 Kudos
1 Reply
by Anonymous User
Not applicable

I had exactly the same problem and I understand your frustration.  You may already solved the problem, but I thought answering the question may help some people who encountered the same problem.

You don't have to deal with any of the Representation legend object to access legend component of Representation layer.  The below code may contain typos so please be careful if you are trying to copy and past.

import arcpy

mxd_path = "path to your mxd file"
mxd = arcpy.mapping.MapDocument(mxd_path)
legend = arcpy.mapping.ListLayoutElements(mxd, "LEGEND_ELEMENT")[0]
for lyr in legend.listLegendItemLayers():
     legend.updateItem(lyr, use_visible_extent = True)
mxd.save()
del mxd

I hope this helps.

0 Kudos