I've been working on a Python Toolbox that imports runs through a number of steps the last one being to convert labels to annotation so they can be manually placed (I've tried graphics also). I can run the convert to annotation/graphics tools without issue when I manually run them. I can copy and paste the python code into the .pyt file and it runs with no errors, however it doesn't actually convert to annotation/graphics.
If I copy and paste the code to the Python window it runs fine and creates annotation/graphics as expected. I created a new clean pyt with the arcpy.cartography.ConvertLabelsToAnnotation code in the execute section and again it runs without error, but no annotation/graphics are created.
This was working in earlier versions of Pro but I'm not sure when it stopped. I'm currently on 3.2.0.
Has anyone else had this issue and found a way around it?
One thing I see from a few Esri Support cases that seem related to this question is - try adding the following line after you import arcpy in your script:
arcpy.env.overwriteOutput = True
Does the script now produce an output annotation feature class?
I gave this a try and it made no difference. I've also tried (before and after this suggestion) running the tool with and without an existing annotation layer. I'm preferring annotation here but I have also tried the same with graphics and it does not create graphics.
It does leave the labeling turned on for the layers, which would normally be turned off once the annotation tool finishes.
Thanks
I think what may be happening here is that there is an enhancement idea - ENH000111009 - Create a python module to work with annotations in Arcpy - that is in the Product Plan.
There is an ArcGIS Idea to support this here - Modify Annotation Feature Class With ArcPY - Esri Community
So I'm thinking it's currently not possible as you're seeing with the empty annotation and the labels remaining on but does work with the GP tool.
I've done some additional testing and parts of the tool work in different places. I copied and pasted the snippet from the toolbox history into various places only changing a limited amount of code. A direct copy python snippet and paste to the Python window works fine. Since I can't just reference a map using the string name outside of the Python window I added:
aprx = arcpy.mp.ArcGISProject("CURRENT") #Use full path when running in .py
mp = aprx.listMaps("Map")[0]
arcpy.env.overwriteOutput = True
I then use mp as the input_map parameter rather than the string of the map name.
This seems like more of a bug than an enhancement. I'm not trying to manipulate the annotation at all, just simply get it added to the map. It functions to different degrees depending on where it is running.
Agree. Based upon your testing, it does seem like a bug to me as well. I did search the internals for existing bug that mimics this behavior but do not see one. You may want to log this as a bug with Esri Support Services so it's known to the development team.