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

252
2
Jump to solution
11-10-2020 06:40 PM
WilliamParra
New Contributor III

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

Reply
0 Kudos
WilliamParra
New Contributor III

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)
Reply
0 Kudos
2 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?

View solution in original post

Reply
0 Kudos
WilliamParra
New Contributor III

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)
Reply
0 Kudos