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
Did you check Tiled Labels to Annotation?
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.
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!
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):
<SPAN class="keyword token">import</SPAN> arcpy locno <SPAN class="operator token">=</SPAN> arcpy<SPAN class="punctuation token">.</SPAN>GetParameterAsText<SPAN class="punctuation token">(</SPAN><SPAN class="number token">0</SPAN><SPAN class="punctuation token">)</SPAN> year <SPAN class="operator token">=</SPAN> locno<SPAN class="punctuation token">[</SPAN><SPAN class="number token">3</SPAN><SPAN class="punctuation token">:</SPAN><SPAN class="number token">7</SPAN><SPAN class="punctuation token">]</SPAN> arcpy<SPAN class="punctuation token">.</SPAN>AddMessage<SPAN class="punctuation token">(</SPAN><SPAN class="string token">'locno: '</SPAN> <SPAN class="operator token">+</SPAN> locno<SPAN class="punctuation token">)</SPAN> workspace <SPAN class="operator token">=</SPAN> <SPAN class="string token">"O:/plan/luam/1p2007/"</SPAN> <SPAN class="operator token">+</SPAN> year <SPAN class="operator token">+</SPAN> <SPAN class="string token">"/"</SPAN> <SPAN class="operator token">+</SPAN> locno <SPAN class="operator token">+</SPAN> <SPAN class="string token">"/data_for_item.gdb"</SPAN> <SPAN class="comment token">#|data"</SPAN> arcpy<SPAN class="punctuation token">.</SPAN>env<SPAN class="punctuation token">.</SPAN>workspace <SPAN class="operator token">=</SPAN> workspace mxd <SPAN class="operator token">=</SPAN> <SPAN class="string token">"O:/plan/luam/1p2007/"</SPAN> <SPAN class="operator token">+</SPAN> year <SPAN class="operator token">+</SPAN> <SPAN class="string token">"/"</SPAN> <SPAN class="operator token">+</SPAN> locno <SPAN class="operator token">+</SPAN> <SPAN class="string token">"/"</SPAN> <SPAN class="operator token">+</SPAN> locno <SPAN class="operator token">+</SPAN> <SPAN class="string token">"-existing_proposed.mxd"</SPAN> mxd <SPAN class="operator token">=</SPAN> arcpy<SPAN class="punctuation token">.</SPAN>mapping<SPAN class="punctuation token">.</SPAN>MapDocument<SPAN class="punctuation token">(</SPAN>mxd<SPAN class="punctuation token">)</SPAN> dataframe <SPAN class="operator token">=</SPAN> arcpy<SPAN class="punctuation token">.</SPAN>mapping<SPAN class="punctuation token">.</SPAN>ListDataFrames<SPAN class="punctuation token">(</SPAN>mxd<SPAN class="punctuation token">,</SPAN> <SPAN class="string token">"*"</SPAN><SPAN class="punctuation token">)</SPAN><SPAN class="punctuation token">[</SPAN><SPAN class="number token">0</SPAN><SPAN class="punctuation token">]</SPAN> frameExtent <SPAN class="operator token">=</SPAN> dataframe<SPAN class="punctuation token">.</SPAN>extent XMAX <SPAN class="operator token">=</SPAN> frameExtent<SPAN class="punctuation token">.</SPAN>XMax XMIN <SPAN class="operator token">=</SPAN> frameExtent<SPAN class="punctuation token">.</SPAN>XMin YMAX <SPAN class="operator token">=</SPAN> frameExtent<SPAN class="punctuation token">.</SPAN>YMax YMIN <SPAN class="operator token">=</SPAN> frameExtent<SPAN class="punctuation token">.</SPAN>YMin pnt1 <SPAN class="operator token">=</SPAN> arcpy<SPAN class="punctuation token">.</SPAN>Point<SPAN class="punctuation token">(</SPAN>XMIN<SPAN class="punctuation token">,</SPAN> YMIN<SPAN class="punctuation token">)</SPAN> pnt2 <SPAN class="operator token">=</SPAN> arcpy<SPAN class="punctuation token">.</SPAN>Point<SPAN class="punctuation token">(</SPAN>XMIN<SPAN class="punctuation token">,</SPAN> YMAX<SPAN class="punctuation token">)</SPAN> pnt3 <SPAN class="operator token">=</SPAN> arcpy<SPAN class="punctuation token">.</SPAN>Point<SPAN class="punctuation token">(</SPAN>XMAX<SPAN class="punctuation token">,</SPAN> YMAX<SPAN class="punctuation token">)</SPAN> pnt4 <SPAN class="operator token">=</SPAN> arcpy<SPAN class="punctuation token">.</SPAN>Point<SPAN class="punctuation token">(</SPAN>XMAX<SPAN class="punctuation token">,</SPAN> YMIN<SPAN class="punctuation token">)</SPAN> array <SPAN class="operator token">=</SPAN> arcpy<SPAN class="punctuation token">.</SPAN>Array<SPAN class="punctuation token">(</SPAN><SPAN class="punctuation token">)</SPAN> array<SPAN class="punctuation token">.</SPAN>add<SPAN class="punctuation token">(</SPAN>pnt1<SPAN class="punctuation token">)</SPAN> array<SPAN class="punctuation token">.</SPAN>add<SPAN class="punctuation token">(</SPAN>pnt2<SPAN class="punctuation token">)</SPAN> array<SPAN class="punctuation token">.</SPAN>add<SPAN class="punctuation token">(</SPAN>pnt3<SPAN class="punctuation token">)</SPAN> array<SPAN class="punctuation token">.</SPAN>add<SPAN class="punctuation token">(</SPAN>pnt4<SPAN class="punctuation token">)</SPAN> array<SPAN class="punctuation token">.</SPAN>add<SPAN class="punctuation token">(</SPAN>pnt1<SPAN class="punctuation token">)</SPAN> polygon <SPAN class="operator token">=</SPAN> arcpy<SPAN class="punctuation token">.</SPAN>Polygon<SPAN class="punctuation token">(</SPAN>array<SPAN class="punctuation token">)</SPAN> arcpy<SPAN class="punctuation token">.</SPAN>CopyFeatures_management<SPAN class="punctuation token">(</SPAN>polygon<SPAN class="punctuation token">,</SPAN> <SPAN class="string token">"Polygon_Extent"</SPAN><SPAN class="punctuation token">)</SPAN> result <SPAN class="operator token">=</SPAN> <SPAN class="token boolean">True</SPAN> arcpy<SPAN class="punctuation token">.</SPAN>SetParameterAsText<SPAN class="punctuation token">(</SPAN><SPAN class="number token">1</SPAN><SPAN class="punctuation token">,</SPAN> result<SPAN class="punctuation token">)</SPAN><SPAN class="line-numbers-rows"><SPAN></SPAN><SPAN></SPAN><SPAN></SPAN><SPAN></SPAN><SPAN></SPAN><SPAN></SPAN><SPAN></SPAN><SPAN></SPAN><SPAN></SPAN><SPAN></SPAN><SPAN></SPAN><SPAN></SPAN><SPAN></SPAN><SPAN></SPAN><SPAN></SPAN><SPAN></SPAN><SPAN></SPAN><SPAN></SPAN><SPAN></SPAN><SPAN></SPAN><SPAN></SPAN><SPAN></SPAN><SPAN></SPAN><SPAN></SPAN><SPAN></SPAN><SPAN></SPAN><SPAN></SPAN><SPAN></SPAN></SPAN>
Script for CreateAnnotation:
<SPAN class="keyword token">import</SPAN> arcpy locno <SPAN class="operator token">=</SPAN> arcpy<SPAN class="punctuation token">.</SPAN>GetParameterAsText<SPAN class="punctuation token">(</SPAN><SPAN class="number token">0</SPAN><SPAN class="punctuation token">)</SPAN> year <SPAN class="operator token">=</SPAN> locno<SPAN class="punctuation token">[</SPAN><SPAN class="number token">3</SPAN><SPAN class="punctuation token">:</SPAN><SPAN class="number token">7</SPAN><SPAN class="punctuation token">]</SPAN> arcpy<SPAN class="punctuation token">.</SPAN>AddMessage<SPAN class="punctuation token">(</SPAN><SPAN class="string token">'locno: '</SPAN> <SPAN class="operator token">+</SPAN> locno<SPAN class="punctuation token">)</SPAN> mxd <SPAN class="operator token">=</SPAN> <SPAN class="string token">"O:/plan/luam/1p2007/"</SPAN> <SPAN class="operator token">+</SPAN> year <SPAN class="operator token">+</SPAN> <SPAN class="string token">"/"</SPAN> <SPAN class="operator token">+</SPAN> locno <SPAN class="operator token">+</SPAN> <SPAN class="string token">"/"</SPAN> <SPAN class="operator token">+</SPAN> locno <SPAN class="operator token">+</SPAN> <SPAN class="string token">"-existing_proposed.mxd"</SPAN> Polygon_Extent <SPAN class="operator token">=</SPAN> <SPAN class="string token">"O:/plan/luam/1p2007/"</SPAN> <SPAN class="operator token">+</SPAN> year <SPAN class="operator token">+</SPAN> <SPAN class="string token">"/"</SPAN> <SPAN class="operator token">+</SPAN> locno <SPAN class="operator token">+</SPAN> <SPAN class="string token">"/data_for_item.gdb/Polygon_Extent"</SPAN> outGdb <SPAN class="operator token">=</SPAN> <SPAN class="string token">"O:/plan/luam/1p2007/"</SPAN> <SPAN class="operator token">+</SPAN> year <SPAN class="operator token">+</SPAN> <SPAN class="string token">"/"</SPAN> <SPAN class="operator token">+</SPAN> locno <SPAN class="operator token">+</SPAN> <SPAN class="string token">"/data_for_item.gdb"</SPAN> GroupAnno <SPAN class="operator token">=</SPAN> <SPAN class="string token">"GroupAnno"</SPAN> <SPAN class="comment token"># Process: Tiled Labels To Annotation</SPAN> arcpy<SPAN class="punctuation token">.</SPAN>TiledLabelsToAnnotation_cartography<SPAN class="punctuation token">(</SPAN>mxd<SPAN class="punctuation token">,</SPAN> <SPAN class="string token">"Layers"</SPAN><SPAN class="punctuation token">,</SPAN> Polygon_Extent<SPAN class="punctuation token">,</SPAN> outGdb<SPAN class="punctuation token">,</SPAN> GroupAnno<SPAN class="punctuation token">,</SPAN> <SPAN class="string token">"Anno"</SPAN><SPAN class="punctuation token">,</SPAN> <SPAN class="string token">"4000"</SPAN><SPAN class="punctuation token">,</SPAN> <SPAN class="string token">""</SPAN><SPAN class="punctuation token">,</SPAN> <SPAN class="string token">""</SPAN><SPAN class="punctuation token">,</SPAN> <SPAN class="string token">""</SPAN><SPAN class="punctuation token">,</SPAN> <SPAN class="string token">""</SPAN><SPAN class="punctuation token">,</SPAN> <SPAN class="string token">"STANDARD"</SPAN><SPAN class="punctuation token">,</SPAN> <SPAN class="string token">"GENERATE_UNPLACED_ANNOTATION"</SPAN><SPAN class="punctuation token">)</SPAN> result <SPAN class="operator token">=</SPAN> <SPAN class="token boolean">True</SPAN> arcpy<SPAN class="punctuation token">.</SPAN>SetParameterAsText<SPAN class="punctuation token">(</SPAN><SPAN class="number token">1</SPAN><SPAN class="punctuation token">,</SPAN> result<SPAN class="punctuation token">)</SPAN><SPAN class="line-numbers-rows"><SPAN></SPAN><SPAN></SPAN><SPAN></SPAN><SPAN></SPAN><SPAN></SPAN><SPAN></SPAN><SPAN></SPAN><SPAN></SPAN><SPAN></SPAN><SPAN></SPAN><SPAN></SPAN><SPAN></SPAN><SPAN></SPAN></SPAN>
Great. Thanks! This is exactly what I am trying to do in Data Driven pages. A script will save tons of clicks.
Thanks for the reminder James. Yes, I’m just ironing out a few bugs and will then post the solution.
Did this work for you Chris?
Thanks. I will look into that!
Přihlášení členové mohou přispívat, sledovat aktualizace a další. Jste tu noví? Zaregistrujte si bezplatný účet.
Find useful guides, FAQs, and documents to help you navigate and make the most of Esri Community.