labels do not apply when using listLayers('layer.name')[0].symbology

359
3
05-06-2022 08:43 AM
kradijaf
New Contributor III

Trying to automate map creating process. When applying symbology from model map to new map using the code below, everything except labeling applies. The new layer is a part of layer in model map (it´s a clip of layer in model map), I want to use the same field and labeling settings, just need it to apply to layer in new map with same settings as in model map. Data type of the field is equal in both layers too. The problem is somewhere in rows 5-7, layer names, project, listed maps etc. are fine. 

 

Can´t find an article about symbology and mainly labeling properties/methods.

 

Using Python 3.7.11 and ArcGIS Pro 2.9

 

 

aprx=a.mp.ArcGISProject('F:\path\to\project\project.aprx")
m1=aprx.listMaps('Model')[0]
m2=aprx.listMaps('New')[0]

sym=m2.listLayers('layer1')[0].symbology
apply_to=m1.listLayers('layer2')[0]
apply_to.symbology=sym

aprx.save()
del aprx

 

 

 

0 Kudos
3 Replies
RhettZufelt
MVP Frequent Contributor

Not sure if it makes a difference, but you mention two maps (model map and new map), but you are setting m1 and m2 to the same map.

Labeling is not part of the symbology, but handled with the LabelClass.

Should be able to use that to copy/update the labeling.

R_

 

kradijaf
New Contributor III

Thanks for spotting the mistake, made it when making this post, in my script, m1 and m2 are different maps.

0 Kudos
RhettZufelt
MVP Frequent Contributor

You could also just grab the layer and save to a layer file which stores symbology, labels, selections, popups, etc.

Then, just apply symbology from layer file and all will be copied to the new layer at once.

R_