AnsweredAssumed Answered

Copying Text Symbol using Python in ArcGIS Pro

Question asked by maxreis6 on Oct 9, 2018

I'm working on a script that takes a subset copy of a layer, and I'd like to make sure the Text Symbol used for Label Class gets maintained. While working in the map, using the "Apply Symbology From Layer Tool" (from the Data Management Toolbox) applys the text symbology to the input layer from the symbology layer.

 

However, using the same tool in the Python Window does not copy over the text symbology. The code is retrieved from the geoprocessing history  by using "Copy Python Command"; the command looks like:

arcpy.management.ApplySymbologyFromLayer("WGRES_Layer_", "WGRES_Layer", None, "DEFAULT")

 

I noticed that the command's syntax is listed as slightly different on the ESRI documentation for the tool; but the resulting command still does not have any effect on the text symbology in the map (

 

In my research, i also noticed that there is a manual way to get the symbology by accessing the layer object in ArcPy:

 

import arcpy
aprx = arcpy.mp.ArcGISProject("current")
m = aprx.listMaps("Map")[0]
lyr = m.listLayers("WGRES_Layer")[0]
sym = lyr.symbology
newlyr = m.listLayers("WGRES_Layer_")[0]
newlyr.symbology = sym
aprx.save()

 

I'm not sure what I'm missing here. Does anyone know of any other ways to use python to edit the text symbology for a label class?

Outcomes