Convert Labels To Annotation

2640
8
Jump to solution
12-13-2016 06:31 AM
ChrisHolmes
Occasional Contributor III

Hello everyone,

Wondering if there is a way to complete the following using arcpy.

Any insights appreciated. My searches so far haven't turned much up.

Thanks,

Chris

0 Kudos
1 Solution

Accepted Solutions
JayantaPoddar
MVP Esteemed Contributor
8 Replies
JayantaPoddar
MVP Esteemed Contributor

Did you check Tiled Labels to Annotation?



Think Location
ChrisHolmes
Occasional Contributor III

Thanks. I will look into that!

0 Kudos
JamesCarpenter2
New Contributor

Did this work for you Chris? 

0 Kudos
ChrisHolmes
Occasional Contributor III

Thanks for the reminder James. Yes, I’m just ironing out a few bugs and will then post the solution.

0 Kudos
JamesCarpenter3
New Contributor

Great. Thanks! This is exactly what I am trying to do in Data Driven pages. A script will save tons of clicks. 

0 Kudos
ChrisHolmes
Occasional Contributor III

Here's the solution I have to date. It is in the context of a model at this point. I plan to at some point move it into a single script tool.

Script for CreatePolygonE (found the base code for this on geonet from Jake Skinner - Thanks Jake):

import arcpy
locno = arcpy.GetParameterAsText(0)
year = locno[3:7]
arcpy.AddMessage('locno: ' + locno)
workspace = "O:/plan/luam/1p2007/" + year + "/" + locno + "/data_for_item.gdb" #|data"
arcpy.env.workspace = workspace
mxd = "O:/plan/luam/1p2007/" + year + "/" + locno + "/" + locno + "-existing_proposed.mxd"
mxd = arcpy.mapping.MapDocument(mxd)
dataframe = arcpy.mapping.ListDataFrames(mxd, "*")[0]
frameExtent = dataframe.extent
XMAX = frameExtent.XMax
XMIN = frameExtent.XMin
YMAX = frameExtent.YMax
YMIN = frameExtent.YMin
pnt1 = arcpy.Point(XMIN, YMIN)
pnt2 = arcpy.Point(XMIN, YMAX)
pnt3 = arcpy.Point(XMAX, YMAX)
pnt4 = arcpy.Point(XMAX, YMIN)
array = arcpy.Array()
array.add(pnt1)
array.add(pnt2)
array.add(pnt3)
array.add(pnt4)
array.add(pnt1)
polygon = arcpy.Polygon(array)
arcpy.CopyFeatures_management(polygon, "Polygon_Extent")
result = True
arcpy.SetParameterAsText(1, result)

Script for CreateAnnotation:

import arcpy
locno = arcpy.GetParameterAsText(0)
year = locno[3:7]
arcpy.AddMessage('locno: ' + locno)
mxd = "O:/plan/luam/1p2007/" + year + "/" + locno + "/" + locno + "-existing_proposed.mxd"
Polygon_Extent = "O:/plan/luam/1p2007/" + year + "/" + locno + "/data_for_item.gdb/Polygon_Extent"
outGdb = "O:/plan/luam/1p2007/" + year + "/" + locno + "/data_for_item.gdb"
GroupAnno = "GroupAnno"
# Process: Tiled Labels To Annotation
arcpy.TiledLabelsToAnnotation_cartography(mxd, "Layers", Polygon_Extent, outGdb,
        GroupAnno, "Anno", "4000", "", "", "", "", "STANDARD", "GENERATE_UNPLACED_ANNOTATION")
result = True
arcpy.SetParameterAsText(1, result)
ChrisHolmes
Occasional Contributor III

So, while I was able to get this working and save the annotation to a file geodatabase. The "Convert Labels to Annotation" form in the manual arcMap process to give you the ability to save the annotation in the existing mxd file. I was not able to find a way to accomplish that with arcpy. Is that not possible?

Thanks all!

0 Kudos
BrittneyWhite1
Esri Contributor

From this GeoNet post, Annotation classes not visible after adding an annotation layer, it looks like you can  use  MakeFeatureLayer_management to create a layer and then add the layer using mapping.AddLayer.

0 Kudos