Convert Labels to Graphics CIM Path error

737
2
Jump to solution
11-01-2022 02:31 PM
by Anonymous User
Not applicable

I am trying to add a layer to a map, then convert the labels to graphics. But when I run the script from a custom toolbox script inside the map document it gives me this strange error that I couldn't find any info on: 

Invalid CIM dataset for path: CIMPATH=map/ground.json

Scott431_5-1667337842121.png

Scott431_1-1667337299666.png

 

When there is another layer in the map document, it is referenced in the bottom of the error instead of "map/ground". I set the Convert to Graphics tool to only work on a "single_layer", so I don't know how other layers could possibly be involved. It's not the main source of the error, but curious none-the-less. 

Scott431_3-1667337553450.png

 

When I run the script as a standalone script it works fine, no other changes necessary!

Scott431_2-1667337434219.png

 

And here's another twist. It works when I run it from a custom toolbox script in the map, IF... I add the layer by hand before running the script. And before you suggest it, no, grabbing the layer from map.listLayers() after adding it does not fix the original version of the script. It has to literally be added by hand for this to work.

Scott431_4-1667337699932.png

 

I've tried comparing the object type when I added the layer by hand vs. when I added it through python, and it's exactly the same. I really have no clue what the difference is. But I need to be able to run this through a map document toolbox.

0 Kudos
2 Solutions

Accepted Solutions
by Anonymous User
Not applicable

I figured out a workaround.

Just use: map.addDataFromPath()

Instead of:
arcpy.management.MakeFeatureLayer()
map.addLayer()

Still seems like a glitch, but hey this works...

View solution in original post

0 Kudos
by Anonymous User
Not applicable

Actually... update needed.

You also need to pull the reference to the layer from your map after you add it.
So it would be:
added_lyr = map.addDataFromPath(my_path)
useful_lyr = map.listLayers(added_lyr.name)[0]

 

Then use the "useful_lyr" as the input to the Convert to Graphics tool.
Then add that graphics results to your map.


If you use the results from the addDataFromPath tool as the input to Convert to Graphics, instead of grabbing the layer reference from the map, it will do some funky stuff, such as added an extra copy of the graphics to your map, and also not let you edit the text of the graphics label. No clue why.

View solution in original post

0 Kudos
2 Replies
by Anonymous User
Not applicable

I figured out a workaround.

Just use: map.addDataFromPath()

Instead of:
arcpy.management.MakeFeatureLayer()
map.addLayer()

Still seems like a glitch, but hey this works...

0 Kudos
by Anonymous User
Not applicable

Actually... update needed.

You also need to pull the reference to the layer from your map after you add it.
So it would be:
added_lyr = map.addDataFromPath(my_path)
useful_lyr = map.listLayers(added_lyr.name)[0]

 

Then use the "useful_lyr" as the input to the Convert to Graphics tool.
Then add that graphics results to your map.


If you use the results from the addDataFromPath tool as the input to Convert to Graphics, instead of grabbing the layer reference from the map, it will do some funky stuff, such as added an extra copy of the graphics to your map, and also not let you edit the text of the graphics label. No clue why.

0 Kudos