Select to view content in your preferred language

ArcPy in Pro more limited than in Desktop?

3500
15
09-08-2017 10:05 AM
LevNagdimunov
Occasional Contributor

ArcPy for ArcGIS Pro seems more limited than the Desktop ArcPy in crucial ways.

The older ArcPy had the ``arcpy.mapping.UpdateLayer`` function, which could (with the last parameter set to true) update symbology on a layer from a template layer. No such function (or replacement for it) appears to exist in the new ArcPy, unless I am missing it? This is a crucial capability given how limited ArcPy is in terms of directly manipulating symbology, for example for rasters there seems to be essentially no way to modify any symbology now.

There is still the ``arcpy.ApplySymbologyFromLayer_management`` tool. However this tool does not work for all layers (nor did it in Desktop), for example it executes without error but seems to do nothing for symbology of a raster layer of a mosaic, whether you apply symbology from a raster layer to the mosaic raster layer or symbology from an entire mosaic to the entire mosaic.

Separately but related, the functionality of ``arcpy.mapping.UpdateLayerTime`` is also gone, and seems to have no replacement. The entire ability to deal with time appears to be gone, for example layer.time no longer seems to exist for time-enabled layers (also according to the docs).

I am surprised to find such crucial features removed. Has something replaced them that I was not able to find, or is something slated to?

Tags (2)
15 Replies
JustinConnerWR
Frequent Contributor

Was the raster stretch support implemented, and if so, any way to switch to "custom" stats w/ arcpy to set min/max the same across a set of rasters?

0 Kudos
HopeWorkswell
Emerging Contributor

Hello Lev:

I've been using Pro 2.0.1 now and I ran into the same question as you did. I saw this thread and I came up with a solution, though it might not suit for every cases, but it is still a solution!

The idea is that inside the arcpy.mp layer class(the class you use Map.listLayers()[0] to get) there's a property called symbology. It has read and write access. So what you can do is to pre-set a symbology lyrx file and add it as layer class into map class, then extract it's symbology as a variable. Then you remove this symbology layer, add the layer you really want, assign the symbology variable as the new value for the layer's symbology property. Then you save it and export images.

Here is my code:

output_aprx = arcpy.mp.ArcGISProject(output_aprx_pth)# read it as object using arcpy, then to modify it
#Working on converting input feature class to a layer inside aprx project file
Map = output_aprx.listMaps("Map")[0]
Layout = output_aprx.listLayouts()[0]
title = Layout.listElements("TEXT_ELEMENT")[0]# Get the title object
title.text = "DC "+ outname# Change the text message of title to what we want

if symbology == 0:
   Map.addLayer(input_lyrF, "TOP")
else:
   sym_lyrF = arcpy.mp.LayerFile(symbology)
   Map.addLayer(sym_lyrF, "TOP")
   sym_layer = Map.listLayers()[0]
   sym_obj = sym_layer.symbology
   Map.removeLayer(sym_layer)
   Map.addLayer(input_lyrF)
   input_layer = Map.listLayers()[0]
   input_layer.symbology = sym_obj
output_aprx.save()# Save the edits
Layout.exportToJPEG(outmaps_path + name_element + ".jpg", resolution = out_resolution)

I tried it on simple symbol and graduate color, everything works fine. 

LevNagdimunov
Occasional Contributor

Thanks for the reply Hope. I would guess that this works for the layers whose symbology manipulation is supported, which are listed under the Symbology class description for ArcGIS Pro. I believe the two you listed are on there. However, the following exception is raised when I try this for stretched or RGB symbology,

NameError: The attribute 'symbology' is not supported on this instance of Layer.

When simply getting the symbology attribute, things work (although it has no real properties to look at for non-supported symbologies). This error is coming from setting the symbology attribute, where ArcPy catches an exception stemming from,

gp.getIDMessage(89013,"The attribute %r is not supported on this instance of %s.") %

Please let me know if you think I am doing something wrong here.

0 Kudos
BorjaParés_Fuente
Emerging Contributor

Hi,

I'm experience the same behavior with a raster layer (extension .jp2) and trying to apply RGB symbology.

Is there any workaround to solve this issue?

Thanks in advance.

0 Kudos
JeffBarrette
Esri Regular Contributor

We unfortunately have not extended the number of supported renderers and this includes the 2.3 release due out at the beginning of next year.  We currently plan to have something available at 2.4 that will give you finer grained access to ALL renderers.  

Jeff - arcpy.mp team

0 Kudos
StefanKoch
New Contributor

A few years later, still no such functions UpdateLayer and UpdateTime in arcpy.mp - why? Still have to use ArcMap?

0 Kudos