This script does not work - I need to button up LABEL in properties of layer in a layout ... and it does not well. Where I have a mistake? Thanke You very much. Veronika
"...
nnulta.showlabels = True
nnulta_cim = nnulta.getDefinition('V2') # vytahne format znaceni
nnultaz = nnulta_cim.labelClasses[0] # sahne na aktualni tridu znaceni
nnultaz.type = 'CIMLabelClass'
nnultaz.expression = '$feature.SPT'
nnultaz.expressionEngine = 'Arcade' # jazyk znaceni
nnultaz.featuresToLabel = 'AllVisibleFeatures'
nnultaz.name = 'Class 1'
nnultaz.priority = -1
nnultaz.visibility = -1
nnultaz.iD = -1
nnulta.setDefinition(nnulta_cim) # prepise format znaceni... doufam
nnulta.showlabels = True
nnulta_cim = nnulta.getDefinition('V2')
nnulta.setDefinition(nnulta_cim)
projektik.save()
..."
Solved! Go to Solution.
I tried the following code in my APRX project via notebook
aprx=arcpy.mp.ArcGISProject("CURRENT")
map = aprx.listMaps()[0]
layer = map.listLayers()[0]
print("Supports labels", layer.supports("SHOWLABELS"))
cim = layer.getDefinition('V2')
cim_lc = cim.labelClasses[0]
cim_lc.type = 'CIMLabelClass'
cim_lc.expression = '$feature.Name'
cim_lc.expressionEngine='Arcade'
cim_lc.featuresToLabel = 'AllVisibleFeatures'
cim_lc.name = 'Class 1'
cim_lc.priority = -1
cim_lc.visibility = True
cim_lc.iD = -1
layer.setDefinition(cim)
layer.showLabels=True
aprx.save()
I changed "visibility=-1" to "visibility=True" but it worked either way.
The test for layer.supports("SHOWLABELS") is False when labeling is turned off and to get it to change to True I can just do layer.showLabels=True as in my code sample. So that test is useless.
@VeronikaVlčková You need to give us more context since the sample you sent actually worked for me. Can you show the rest of the code? Can you upload a minimal APRX file??
cim access is discussed here for labels
LabelClass—ArcGIS Pro | Documentation
check to see if your layer supports labelling as in the help
... yes, of course. To this help I am foolishly gapeing the whole week. Veronika
I tried the following code in my APRX project via notebook
aprx=arcpy.mp.ArcGISProject("CURRENT")
map = aprx.listMaps()[0]
layer = map.listLayers()[0]
print("Supports labels", layer.supports("SHOWLABELS"))
cim = layer.getDefinition('V2')
cim_lc = cim.labelClasses[0]
cim_lc.type = 'CIMLabelClass'
cim_lc.expression = '$feature.Name'
cim_lc.expressionEngine='Arcade'
cim_lc.featuresToLabel = 'AllVisibleFeatures'
cim_lc.name = 'Class 1'
cim_lc.priority = -1
cim_lc.visibility = True
cim_lc.iD = -1
layer.setDefinition(cim)
layer.showLabels=True
aprx.save()
I changed "visibility=-1" to "visibility=True" but it worked either way.
The test for layer.supports("SHOWLABELS") is False when labeling is turned off and to get it to change to True I can just do layer.showLabels=True as in my code sample. So that test is useless.
@VeronikaVlčková You need to give us more context since the sample you sent actually worked for me. Can you show the rest of the code? Can you upload a minimal APRX file??