Select to view content in your preferred language

How to enable in Python script visibility of labels, prepared in CIMaccess

1605
3
Jump to solution
02-22-2022 08:09 AM
VeronikaVlčková
New Contributor

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()

..."

0 Kudos
1 Solution

Accepted Solutions
Brian_Wilson
Honored Contributor

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??

 

View solution in original post

0 Kudos
3 Replies
DanPatterson
MVP Esteemed Contributor

cim access is discussed here for labels

LabelClass—ArcGIS Pro | Documentation

check to see if your layer supports labelling as in the help


... sort of retired...
0 Kudos
VeronikaVlčková
New Contributor

... yes, of course. To this help I am foolishly gapeing the whole week. Veronika

0 Kudos
Brian_Wilson
Honored Contributor

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??

 

0 Kudos