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)
Solved! Go to Solution.
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?
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
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?
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