<?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: Iterate an annotation feature class in arcpy in Python Snippets Questions</title>
    <link>https://community.esri.com/t5/python-snippets-questions/iterate-an-annotation-feature-class-in-arcpy/m-p/868314#M629</link>
    <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;P&gt;How long does this take to run on 300,000+ records?&lt;/P&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
    <pubDate>Wed, 11 Jul 2018 18:51:25 GMT</pubDate>
    <dc:creator>MichaelVolz</dc:creator>
    <dc:date>2018-07-11T18:51:25Z</dc:date>
    <item>
      <title>Iterate an annotation feature class in arcpy</title>
      <link>https://community.esri.com/t5/python-snippets-questions/iterate-an-annotation-feature-class-in-arcpy/m-p/868313#M628</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;P&gt;I finally figured out how to iterate an annotation feature class in arcpy to update its attributes.&lt;/P&gt;&lt;P&gt;You cannot use a cursor , it just generates errors. You cannot directly use SQL and bypass arcpy because the attribute columns are just for show, the real data is hidden in a binary column you can't see in ArcGIS.&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;But you &lt;STRONG&gt;can&lt;/STRONG&gt; use CalculateField_management.&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;Roughly put,&lt;/P&gt;&lt;BLOCKQUOTE class="jive_macro_quote jive-quote jive_text_macro"&gt;&lt;P&gt;codeblock = """def writekv(k, v)&lt;/P&gt;&lt;P&gt;&amp;nbsp; # do some calculation here, put it in "newvalue'&lt;BR /&gt;&amp;nbsp; return newvalue&lt;BR /&gt;"""&lt;/P&gt;&lt;P&gt;expression = "writekv(!%s!, !%s!)" % (keyfield, valuefield)&lt;/P&gt;&lt;P&gt;arcpy.CalculateField_management(layer, fieldname, expression, "PYTHON_9.3", codeblock)&lt;/P&gt;&lt;/BLOCKQUOTE&gt;&lt;P&gt;where keyfield and valuefield are the names of attribute fields you want to use&lt;/P&gt;&lt;P&gt;and fieldname is the name of the attribute being calculated.&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;All the normal python rules apply of course - indentation and you can use "import" and so on. I have been writing functions in the main body of my python script so that I can write unit tests, get the calculations correct, before getting into wrapping the code in a "codeblock" string. In this case the code looks something like this&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;BLOCKQUOTE class="jive_macro_quote jive-quote jive_text_macro"&gt;&lt;P&gt;#big long lookup table here&lt;/P&gt;&lt;P&gt;lut = { 1:"fine", 2:"dandy" }&lt;/P&gt;&lt;P&gt;def myfunc(x):&lt;/P&gt;&lt;P&gt;&amp;nbsp; # do some long python thing here&lt;/P&gt;&lt;P&gt;&amp;nbsp; y = lut&lt;X&gt; # use a lookup table you've carefully tested in advance&lt;/X&gt;&lt;/P&gt;&lt;P&gt;&amp;nbsp; return y&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;codeblock="""from thisfile import myfunc&lt;/P&gt;&lt;P&gt;def f(x):&lt;/P&gt;&lt;P&gt;&amp;nbsp; return myfunc(x)"""&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;arcpy.CalculateField_management(layer, "SomeTextField", "f(!INTEGERFIELD!)", "PYTHON_9.3", codeblock)&lt;/P&gt;&lt;/BLOCKQUOTE&gt;&lt;P&gt;This puts just the minimum needed inside "codeblock" (making it all much easier to debug) and in my example runs a function called myfunc that you can test separately.&lt;/P&gt;&lt;P&gt;This&amp;nbsp;assumes all your code is in a file called "thisfile.py". In "codeblock" it does an import, that is so that the copy of python running in the field calculator can use a lookup table called lut that's declared outside the function "myfunc".&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;I have to&amp;nbsp;adjust the font sizes in 300,000+ records and this is working for me.&lt;/P&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Wed, 11 Jul 2018 18:20:55 GMT</pubDate>
      <guid>https://community.esri.com/t5/python-snippets-questions/iterate-an-annotation-feature-class-in-arcpy/m-p/868313#M628</guid>
      <dc:creator>BrianWilson</dc:creator>
      <dc:date>2018-07-11T18:20:55Z</dc:date>
    </item>
    <item>
      <title>Re: Iterate an annotation feature class in arcpy</title>
      <link>https://community.esri.com/t5/python-snippets-questions/iterate-an-annotation-feature-class-in-arcpy/m-p/868314#M629</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;P&gt;How long does this take to run on 300,000+ records?&lt;/P&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Wed, 11 Jul 2018 18:51:25 GMT</pubDate>
      <guid>https://community.esri.com/t5/python-snippets-questions/iterate-an-annotation-feature-class-in-arcpy/m-p/868314#M629</guid>
      <dc:creator>MichaelVolz</dc:creator>
      <dc:date>2018-07-11T18:51:25Z</dc:date>
    </item>
  </channel>
</rss>

