<?xml version="1.0" encoding="UTF-8"?>
<rss xmlns:content="http://purl.org/rss/1.0/modules/content/" xmlns:dc="http://purl.org/dc/elements/1.1/" xmlns:rdf="http://www.w3.org/1999/02/22-rdf-syntax-ns#" xmlns:taxo="http://purl.org/rss/1.0/modules/taxonomy/" version="2.0">
  <channel>
    <title>topic Re: Updating Annotation with Arcpy in ArcGIS Pro in Python Questions</title>
    <link>https://community.esri.com/t5/python-questions/updating-annotation-with-arcpy-in-arcgis-pro/m-p/1219459#M65761</link>
    <description>&lt;P&gt;These are just some ideas from looking at your code.&amp;nbsp; It doesn't appear that "Python" was chosen as the formatting language in the code block, the indentation is missing, and the code isn't documented.&amp;nbsp; This all makes it a little hard to read.&amp;nbsp; So I'll go with what I can see.&amp;nbsp; One hint that I can give you is that if this code is working inside a Notebook, you can use "CURRENT" instead of the name of the project file you are working in and not care about the name and path of the ArcGIS Pro project itself.&lt;/P&gt;&lt;P&gt;Although Python is able to display bytes as a string using print() and implicit representation, it doesn't mean that the resulting string can be converted back into bytes by escaping it or removing special characters.&amp;nbsp; The variable newbytes for instance, is assigned a string, but I bet that's not how it's stored, but rather, how it's represented as a string in Python.&lt;/P&gt;&lt;P&gt;The numbers (e.g. 42.748368221326849) are probably being stored in actual binary form in the geodatabase, not as binary representations of the string of the number.&amp;nbsp; The string "42.748368221326849" would take something in the neighborhood of 19 bytes (ASCII) or 38 bytes (UTF-8) to store, but the number&amp;nbsp;42.748368221326849 would only take 4 bytes (if a float) or 8 bytes (if a double) to store.&amp;nbsp; Bytes are the raw material that everything in computers are based on, and many of what we see and experience with a computer is not stored as string-bytes.&amp;nbsp; The color red, for example, is hardly ever stored in bytes as "red", "RGB(255, 0, 0)", but in binary as 111111110000000000000000 in three bytes.&lt;/P&gt;&lt;P&gt;Hopefully this guides you a solution, but I've just not done anything with annotation in Python before.&lt;/P&gt;&lt;P&gt;Let us know and good luck!&lt;/P&gt;</description>
    <pubDate>Thu, 06 Oct 2022 16:50:07 GMT</pubDate>
    <dc:creator>RogerDunnGIS</dc:creator>
    <dc:date>2022-10-06T16:50:07Z</dc:date>
    <item>
      <title>Updating Annotation with Arcpy in ArcGIS Pro</title>
      <link>https://community.esri.com/t5/python-questions/updating-annotation-with-arcpy-in-arcgis-pro/m-p/1216698#M65733</link>
      <description>&lt;P&gt;Hello,&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;I'm trying to figure out how to use an updatecursor to update an annotation feature class (specifically moving the annotation, not updating the actual text).&amp;nbsp; There's little documentation on this, but from what I can find I think both the shape field and the element fields need to be updated?&amp;nbsp; &amp;nbsp;I'm trying to use an update cursor with hard-coded values first just to see if the annotation updates (it's a single feature), then change it to be more dynamic later on.&amp;nbsp;&amp;nbsp;&lt;/P&gt;&lt;P&gt;I'm also testing with edit sessions to see if that does anything but nothing seems to update.&amp;nbsp; I don't get any errors either, but it seems like the update cursor is not changing anything.&amp;nbsp; Any ideas?&lt;/P&gt;&lt;P&gt;UPDATE:&amp;nbsp; It's definitely an issue with the blob field.&amp;nbsp; Geometry field is updating fine (tested on another polygon layer), but converting the element field to bytes, making changes, and converting back to blob is something I haven't seen any documentation on.&amp;nbsp; Does anyone know the proper encoding?&amp;nbsp; I'm using UTF-8 by default but playing around with different options.&lt;/P&gt;&lt;P&gt;&amp;nbsp; &amp;nbsp;This is my code so far:&amp;nbsp;&lt;/P&gt;&lt;PRE&gt;import arcpy, os, json&lt;BR /&gt;&lt;BR /&gt;aprx = arcpy.mp.ArcGISProject(r"C:\MyProject\MyProject.aprx")&lt;BR /&gt;&lt;BR /&gt;for m in aprx.listMaps():&lt;BR /&gt;print("Map: {0} Layers".format(m.name))&lt;BR /&gt;for lyr in m.listLayers():&lt;BR /&gt;if lyr.name == 'testAnno':&lt;BR /&gt;cursor = arcpy.da.SearchCursor(lyr, ['SHAPE@','Element'])&lt;BR /&gt;for row in cursor:&lt;BR /&gt;#print(row[1].tobytes())&lt;BR /&gt;print(row[1].tobytes())&lt;BR /&gt;print(row[0])&lt;BR /&gt;s = row&lt;BR /&gt;&lt;BR /&gt;#view the &lt;BR /&gt;print(s[0].JSON)&lt;BR /&gt;print(s[1].tobytes())&lt;BR /&gt;&lt;BR /&gt;#hard coded data:&lt;BR /&gt;&lt;BR /&gt;origjson = """{"rings":[[[-75.764363411999966,45.158486504000052],[-73.469080190999989,45.158486504000052],[-73.469080190999989,42.846093335000035],[-75.764363411999966,42.846093335000035],[-75.764363411999966,45.158486504000052]],[[-61.499009848999947,43.715848636000032],[-63.210088402999986,42.185967841000036],[-64.347457697999971,43.458046171000035],[-73.427031740999951,38.791915476000042],[-73.428038225999956,38.791551154000047],[-73.431213794999962,38.792105457000048],[-73.433067308999966,38.794742874000065],[-73.432513005999965,38.797918442000025],[-73.430882073999953,38.799407634000033],[-64.353259686999934,43.46453534300008],[-64.751373533999981,43.909801450000032],[-63.040294979999942,45.439682245000029],[-61.499009848999947,43.715848636000032]]],"spatialReference":{"wkid":4326,"latestWkid":4326}}"""&lt;BR /&gt;&lt;BR /&gt;newjson = """{"rings":[[[-90.580491480999967,44.665072753000061],[-90.580491480999967,42.460838942000066],[-90.579865532999975,42.461430743000051],[-90.577483941999958,42.461614847000078],[-73.428077403999964,38.799780517000045],[-73.427236678999975,38.799506056000041],[-73.425022048999949,38.797163643000033],[-73.425112405999982,38.793941327000027],[-73.427454818999934,38.791726697000058],[-73.42983640999995,38.791542593000031],[-90.57924294899999,42.453376923000064],[-90.58008367299999,42.453651384000068],[-90.580491480999967,42.454082722000066],[-90.580491480999967,42.352679584000043],[-92.875774701999944,42.352679584000043],[-92.875774701999944,44.665072753000061],[-90.580491480999967,44.665072753000061]]],"spatialReference":{"wkid":4326,"latestWkid":4326}}"""&lt;BR /&gt;&lt;BR /&gt;newbytes = """b'\n\x011 \x02*M-92.890214218719606,42.748368221326849;-90.578362387719665,42.7483682213268492\x04test8\x00A\x00\x00\x00\x00\x00\x00\x00\x00z2{"x":-73.4289569073265227,"y":38.7956615549338792}\x81\x01iR\xb2{\xdd\xe5d@\xca\x01\x99\x02{"type":"CIMSimpleLineCallout","lineSymbol":{"type":"CIMLineSymbol","symbolLayers":[{"type":"CIMSolidStroke","enable":true,"capStyle":"Round","joinStyle":"Round","lineStyle3D":"Strip","miterLimit":10,"width":1,"color":{"type":"CIMRGBColor","values":[0,0,0,100]}}]},"autoSnap":true}'"""&lt;BR /&gt;&lt;BR /&gt;origbytes = """b'\n\x011 \x02*M-63.778802929164698,43.241781972225155;-61.466951098164685,43.2417819722251692\x04test8\x00A\x00\x00\x00\x00\x00\x00\x00\x00z2{"x":-73.4289569073265227,"y":38.7956615549338792}\x81\x01iR\xb2{\xdd\xe5d@\xca\x01\x99\x02{"type":"CIMSimpleLineCallout","lineSymbol":{"type":"CIMLineSymbol","symbolLayers":[{"type":"CIMSolidStroke","enable":true,"capStyle":"Round","joinStyle":"Round","lineStyle3D":"Strip","miterLimit":10,"width":1,"color":{"type":"CIMRGBColor","values":[0,0,0,100]}}]},"autoSnap":true}'"""&lt;BR /&gt;&lt;BR /&gt;d = json.loads(s[0].JSON)#getting first record, assuming only 1 anno here for testing&lt;BR /&gt;&lt;BR /&gt;workspace = os.path.dirname(r"C:\Users\dcolombini\Documents\ArcGIS\Projects\MyProject\MyProject.aprx")&lt;BR /&gt;# Start an edit session. Must provide the workspace.&lt;BR /&gt;edit = arcpy.da.Editor(workspace)&lt;BR /&gt;&lt;BR /&gt;# Edit session is started without an undo/redo stack for versioned data&lt;BR /&gt;&lt;BR /&gt;# Set multiuser_mode to False if working with unversioned enterprise gdb data&lt;BR /&gt;edit.startEditing(with_undo=False, multiuser_mode=False)&lt;BR /&gt;&lt;BR /&gt;# Start an edit operation&lt;BR /&gt;edit.startOperation()&lt;BR /&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;BR /&gt;print('\n UPDATING ANNO \n')&lt;BR /&gt;&lt;BR /&gt;ESBlob = bytearray(origbytes, 'utf-8')&lt;BR /&gt;dj = json.dumps(origjson)&lt;BR /&gt;&lt;BR /&gt;# Create update cursor for feature class&lt;BR /&gt;&lt;BR /&gt;for lyr in m.listLayers():&lt;BR /&gt;if lyr.name == 'testanno': &lt;BR /&gt;&lt;BR /&gt;for m in aprx.listMaps():&lt;BR /&gt;print("Map: {0} Layers".format(m.name))&lt;BR /&gt;for lyr in m.listLayers():&lt;BR /&gt;if lyr.name == 'testAnno':&lt;BR /&gt;print('updating anno layer') &lt;BR /&gt;with arcpy.da.UpdateCursor(lyr, ['SHAPE@JSON','Element'], "", sr) as cursor:&lt;BR /&gt;for row in cursor:&lt;BR /&gt;#print(row)&lt;BR /&gt;row[0] = dj #features[0].projectAs('4326')&lt;BR /&gt;row[1] = ESBlob&lt;BR /&gt;cursor.updateRow(row)&lt;BR /&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;BR /&gt;print('\n UPDATE COMPLETE \n')&lt;BR /&gt;#del aprx&lt;BR /&gt;&lt;BR /&gt;# Stop the edit operation.&lt;BR /&gt;edit.stopOperation()&lt;BR /&gt;&lt;BR /&gt;# Stop the edit session and save the changes&lt;BR /&gt;edit.stopEditing(save_changes=True)&lt;BR /&gt;&lt;BR /&gt;&lt;BR /&gt;print('\n Checking new values \n')&lt;BR /&gt;for m in aprx.listMaps():&lt;BR /&gt;print("Map: {0} Layers".format(m.name))&lt;BR /&gt;for lyr in m.listLayers():&lt;BR /&gt;if lyr.name == 'testAnno':&lt;BR /&gt;cursor = arcpy.da.SearchCursor(lyr, ['SHAPE@JSON','Element'])&lt;BR /&gt;for row in cursor:&lt;BR /&gt;print(row[1].tobytes())&lt;BR /&gt;print(row[0])&lt;/PRE&gt;</description>
      <pubDate>Tue, 27 Sep 2022 20:07:05 GMT</pubDate>
      <guid>https://community.esri.com/t5/python-questions/updating-annotation-with-arcpy-in-arcgis-pro/m-p/1216698#M65733</guid>
      <dc:creator>David_Colombini</dc:creator>
      <dc:date>2022-09-27T20:07:05Z</dc:date>
    </item>
    <item>
      <title>Re: Updating Annotation with Arcpy in ArcGIS Pro</title>
      <link>https://community.esri.com/t5/python-questions/updating-annotation-with-arcpy-in-arcgis-pro/m-p/1219459#M65761</link>
      <description>&lt;P&gt;These are just some ideas from looking at your code.&amp;nbsp; It doesn't appear that "Python" was chosen as the formatting language in the code block, the indentation is missing, and the code isn't documented.&amp;nbsp; This all makes it a little hard to read.&amp;nbsp; So I'll go with what I can see.&amp;nbsp; One hint that I can give you is that if this code is working inside a Notebook, you can use "CURRENT" instead of the name of the project file you are working in and not care about the name and path of the ArcGIS Pro project itself.&lt;/P&gt;&lt;P&gt;Although Python is able to display bytes as a string using print() and implicit representation, it doesn't mean that the resulting string can be converted back into bytes by escaping it or removing special characters.&amp;nbsp; The variable newbytes for instance, is assigned a string, but I bet that's not how it's stored, but rather, how it's represented as a string in Python.&lt;/P&gt;&lt;P&gt;The numbers (e.g. 42.748368221326849) are probably being stored in actual binary form in the geodatabase, not as binary representations of the string of the number.&amp;nbsp; The string "42.748368221326849" would take something in the neighborhood of 19 bytes (ASCII) or 38 bytes (UTF-8) to store, but the number&amp;nbsp;42.748368221326849 would only take 4 bytes (if a float) or 8 bytes (if a double) to store.&amp;nbsp; Bytes are the raw material that everything in computers are based on, and many of what we see and experience with a computer is not stored as string-bytes.&amp;nbsp; The color red, for example, is hardly ever stored in bytes as "red", "RGB(255, 0, 0)", but in binary as 111111110000000000000000 in three bytes.&lt;/P&gt;&lt;P&gt;Hopefully this guides you a solution, but I've just not done anything with annotation in Python before.&lt;/P&gt;&lt;P&gt;Let us know and good luck!&lt;/P&gt;</description>
      <pubDate>Thu, 06 Oct 2022 16:50:07 GMT</pubDate>
      <guid>https://community.esri.com/t5/python-questions/updating-annotation-with-arcpy-in-arcgis-pro/m-p/1219459#M65761</guid>
      <dc:creator>RogerDunnGIS</dc:creator>
      <dc:date>2022-10-06T16:50:07Z</dc:date>
    </item>
  </channel>
</rss>

