Select to view content in your preferred language

Convert CIM Object to JSON string

284
3
3 weeks ago
Pukawai
Occasional Contributor

I'm writing a script to generate a UniqueValueRenderer from scratch using 

arcpy.cim.CreateCIMObjectFromClassName('CIMUniqueValueRenderer','V3')

Since this object contains a lot of other CIM objects, I have to make all those as well, but somewhere in there I'm missing something so when writing it into the layer definition, Pro will crash.

Is there a way I can take my newly created CIMUniqueValueRenderer object and convert it to a JSON string so I can see what it contains?

I found a reference to a function GetJSONForCIMObject in another post, but can find no such function in the ArcPy documentation.

0 Kudos
3 Replies
AlfredBaldenweck
MVP Regular Contributor

Well, that's kind of the problem with CIM. Arcane and not well documented. 

x = arcpy.cim.CreateCIMObjectFromClassName('CIMUniqueValueRenderer','V3')
y = arcpy.cim.GetJSONForCIMObject(x, 'V3')
print(y)

'''
{"sampleSize": 10000, "visualVariables": [], 
"colorRamp": {"colorSpace": {"type": "CIMColorSpace"}, "type": "CIMColorRamp"}, 
"defaultSymbol": {"primitiveOverrides": [], 
"symbol": {"type": "CIMSymbol"}, 
"minScale": 0.0, "maxScale": 0.0, 
"scaleDependentSizeVariation": [], 
"minDistance": 0.0, "maxDistance": 0.0, 
"type": "CIMSymbolReference"}, 
"defaultSymbolPatch": "Default", 
"fields": [], "groups": [], 
"useDefaultSymbol": false, 
"valueExpressionInfo": {"returnType": "Default", "type": "CIMExpressionInfo"}, 
"polygonSymbolColorTarget": "Fill", 
"authoringInfo": {"type": "CIMUniqueValueRendererAuthoringInfo"}, "type": "CIMUniqueValueRenderer"}
'''

 

 

Honestly I check out the CIM's github reference and then spend a lot of time using the intellisense in the Python Window in Pro to figure out what I can do. Honestly I hadn't heard of that function before today.

Pukawai
Occasional Contributor

Thank you for this! With some massaging of that output string I should be able to compare it to a .lyrx file and discover what's missing.  Now, if only intellisense worked in notebooks....

AlfredBaldenweck
MVP Regular Contributor

There's a certain irony in how much I've revisited this page over the last two weeks to remind myself of how to get this information.

Hard agree on the notebook. Huge pain.

0 Kudos