Assigning an icon from a .stylx file and rotating it, in arcpy

960
4
09-06-2018 08:45 AM
ZacharyKlaas
New Contributor II

I want to use arcpy to apply a symbol from a .stylx file and then rotate the symbol according to a variable.

Doing this manually, this merely involves clicking on the icon from the gallery pane (where the symbol is located despite being in a .stylx file, the style is clearly regarded as a "project style") and then using "Vary symbology by attribute", "Rotation", selecting the rotation variable, and geographic style for the method of rotation.  It's easy manually, I just want my script to do it automatically.

The relevant code:

   aprx = arcpy.mp.ArcGISProject("CURRENT")
   m = aprx.listMaps("AIS Live Feed")[0]
   l = m.listLayers("xylayer")[0]
   sym = l.symbology

   ##begin code that doesn't work
   sym.renderer.symbol.applySymbolFromGallery("ShipAIS")
   ##end code that doesn't work

It doesn't regard my ShipAIS icon, stored in its .stylx file, as part of my gallery.  I am able to get the icon to change with this code if I select one that is in my default gallery.  Even doing that, though, I don't know how to direct arcpy to rotate an icon once I'm able to access it - there appears to be an "angle" attribute, but I'm not sure how to apply it.

Does anyone know how I might do this?

0 Kudos
4 Replies
MarkTurnbull
New Contributor III

Hi Zachary

Were you able to resolve this problem. I am encountering exactly the same issue.

Thanks

Mark

0 Kudos
ThomasEmge
Esri Contributor

You'll need to get down to the CIM level for the rotation piece.

For more detailed information please take a look at Python CIM access—ArcPy | Documentation as well as an excellent presentation from the Dev Summit https://www.youtube.com/watch?v=RkyzeOgCHe4&list=PLaPDDLTCmy4Ys8vfmC7DbX3FHSsyosvh7&index=28

- Thomas

0 Kudos
MarkTurnbull
New Contributor III

Thanks for responding so quickly Thomas.

My issue is more the python code (applySymbolFromGallery) not recognising symbols in project style files.

0 Kudos
ThomasEmge
Esri Contributor

Are you saying that even with listSymbolsFromGallery(<your_symbol>) you get back an empty list?

I just tried it with Pro 2.6 and it seems to work in my list test case.

and to complete Zachary's code

l.symbology = sym
0 Kudos