Select to view content in your preferred language

Set list of Item objects to the ItemGroup

806
4
05-06-2019 05:48 AM
nita14
by
Frequent Contributor

Dear All,

ArcPy and ArcGIS Pro 2.3.2

Was anybody here successfull in setting a list of sorted Item objects based on features count to the ItemGroup (Unique Value Renderer)? Everytime I try it, I receive an error saying that such attribute cannot be set or ArcGIS Pro crashes unexpectedly. According to the docs, the list if items can be changed. ItemGroup—ArcPy | ArcGIS Desktop. Cannot?

I thought something like the snippet below would do the job, but it doesn't:

sym.renderer.groups[0].items = new_list_of_sorted_Item_objects

Any hints?

Thanks!

Adam

0 Kudos
4 Replies
JoshuaBixby
MVP Esteemed Contributor

It helps to provide more code.  For example, where/how do you get the list of Item objects that you are sorting?  How are you sorting the list? 

That all said, I was able to crash Pro while tinkering with setting the unique value renderer, so there is a defect because the application should never crash completely.  I suggest you open a case with Esri Support.

0 Kudos
nita14
by
Frequent Contributor

Dear Joshua,

Thank you for your support. Here is the code I tried to run:

p = arcpy.mp.ArcGISProject('CURRENT')
m = p.listMaps('Map1')[0]
l = m.listLayers('Lines*')[0]
sym = l.symbology
sym
new_list = []
new_list.append(sym.renderer.groups[0].items[1])
new_list.append(sym.renderer.groups[0].items[2])
new_list.append(sym.renderer.groups[0].items[0])
new_list.append(sym.renderer.groups[0].items[3])
new_listsym.renderer.groups[0].items
sym.renderer.groups[0].items = new_list

and the screenshot with the error:

Well, most probably in the end I will have to direct to Esri Support, but maybe somebody in the community already came across this issue and found a workaround. Keeping my fingers crossed.

BR

Adam

0 Kudos
MichaelWen_Timmons
Occasional Contributor

Has there been an update on this? I am also trying to reorder how the symbols appear in the legends and got an error setting the items property like in the first post. I could update each item's symbol and label but not the values so can't do it that way.

0 Kudos
MichaelWen_Timmons
Occasional Contributor

I am looking for a way to re-order symbology associated with a layer with ArcPy. If I can't do this by modifying uniqueValuesRender is there another way?

The goal is to allow users to pick the order by which symbols appear in the legend. This needs to be done in ArcPy.

0 Kudos