Creating a new label class in Arc Pro using the arcpy CIM

725
3
Jump to solution
11-10-2020 06:40 PM
by Anonymous User
Not applicable

I am attempting to create a new label class for a layer using the arcpy CIM, code below. The new label class gets created, but ArcGIS Pro immediately crashes when I attempt to interact with it in the GUI. I have tried in the python window and in a script. 

aprx = arcpy.mp.ArcGISProject('CURRENT')
m = aprx.listMaps("Map")[0]
lyr = m.listLayers("SOME LAYER")[0]
ldef = lyr.getDefinition('V2')

newlblclass = arcpy.cim.CreateCIMObjectFromClassName('CIMLabelClass','V2')
newlblclass.name = "NEW CLASS"
newlblclass.visibility = True
ldef.labelClasses.append(newlblclass)
lyr.setDefinition(ldef)
0 Kudos
2 Solutions

Accepted Solutions
DuncanHornby
MVP Frequent Contributor

May be there are required properties that need setting? All you set is the name and visibility, but what about the field that the label is derived from?

View solution in original post

0 Kudos
by Anonymous User
Not applicable

Correct. After researching there are many "nested" CIMobjects that make up a label class cim object. All of these objects need to be created and assigned in order for the label class object to function properly. 

Reference: https://pro.arcgis.com/en/pro-app/arcpy/mapping/python-cim-access.htm

View solution in original post

Tags (3)
0 Kudos
3 Replies
DuncanHornby
MVP Frequent Contributor

May be there are required properties that need setting? All you set is the name and visibility, but what about the field that the label is derived from?

0 Kudos
by Anonymous User
Not applicable

Correct. After researching there are many "nested" CIMobjects that make up a label class cim object. All of these objects need to be created and assigned in order for the label class object to function properly. 

Reference: https://pro.arcgis.com/en/pro-app/arcpy/mapping/python-cim-access.htm

Tags (3)
0 Kudos
anyry
by
New Contributor III

Can you please share your label class creation solution? I have the same problem and I can't solve it. Thanks

0 Kudos