<?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: Why AddField script always close the application? in Python Questions</title>
    <link>https://community.esri.com/t5/python-questions/why-addfield-script-always-close-the-application/m-p/1159801#M64239</link>
    <description>&lt;P&gt;After you save your mxd try getting a reference to the data frame and then the layers in the frame and looping through those:&lt;/P&gt;&lt;LI-CODE lang="javascript"&gt;df = arcpy.mapping.ListDataFrames(mxd,"YourDataFrameNameHere")[0]
for fc in arcpy.mapping.ListLayers(mxd, data_frame=df):
    arcpy.AddField_management(fc,"Name","TEXT",field_length=50)&lt;/LI-CODE&gt;&lt;P&gt;This code is going to add the attribute "Name" to every feature class in the data frame.&lt;/P&gt;</description>
    <pubDate>Thu, 31 Mar 2022 10:00:02 GMT</pubDate>
    <dc:creator>KimberlyGarbade</dc:creator>
    <dc:date>2022-03-31T10:00:02Z</dc:date>
    <item>
      <title>Why AddField script always close the application?</title>
      <link>https://community.esri.com/t5/python-questions/why-addfield-script-always-close-the-application/m-p/1159775#M64236</link>
      <description>&lt;P&gt;Dear All,&lt;/P&gt;&lt;P&gt;I've Tried to Add Field using arcpy library but the application always close when I run the code, is there any ideas about this situation?&lt;/P&gt;&lt;P&gt;Thank you&lt;/P&gt;&lt;P&gt;Here is my code:&lt;/P&gt;&lt;DIV&gt;&lt;DIV&gt;&lt;DIV&gt;&lt;DIV&gt;&lt;SPAN&gt;import&lt;/SPAN&gt;&lt;SPAN&gt; arcpy, &lt;/SPAN&gt;&lt;SPAN&gt;os&lt;/SPAN&gt;&lt;SPAN&gt;, &lt;/SPAN&gt;&lt;SPAN&gt;glob&lt;/SPAN&gt;&lt;SPAN&gt;, pythonaddins&lt;/SPAN&gt;&lt;/DIV&gt;&lt;BR /&gt;&lt;DI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gt;.AddField_management(&lt;/SPAN&gt;&lt;SPAN&gt;fc&lt;/SPAN&gt;&lt;SPAN&gt;,&lt;/SPAN&gt;&lt;SPAN&gt;"Name"&lt;/SPAN&gt;&lt;SPAN&gt;,&lt;/SPAN&gt;&lt;SPAN&gt;"TEXT"&lt;/SPAN&gt;&lt;SPAN&gt;,&lt;/SPAN&gt;&lt;SPAN&gt;field_length&lt;/SPAN&gt;&lt;SPAN&gt;=&lt;/SPAN&gt;&lt;SPAN&gt;50&lt;/SPAN&gt;&lt;SPAN&gt; &amp;nbsp;)&lt;/SPAN&gt;&lt;/DIV&gt;&lt;/DIV&gt;</description>
      <pubDate>Thu, 31 Mar 2022 07:50:30 GMT</pubDate>
      <guid>https://community.esri.com/t5/python-questions/why-addfield-script-always-close-the-application/m-p/1159775#M64236</guid>
      <dc:creator>TessaKhairaniErmanto</dc:creator>
      <dc:date>2022-03-31T07:50:30Z</dc:date>
    </item>
    <item>
      <title>Re: Why AddField script always close the application?</title>
      <link>https://community.esri.com/t5/python-questions/why-addfield-script-always-close-the-application/m-p/1159801#M64239</link>
      <description>&lt;P&gt;After you save your mxd try getting a reference to the data frame and then the layers in the frame and looping through those:&lt;/P&gt;&lt;LI-CODE lang="javascript"&gt;df = arcpy.mapping.ListDataFrames(mxd,"YourDataFrameNameHere")[0]
for fc in arcpy.mapping.ListLayers(mxd, data_frame=df):
    arcpy.AddField_management(fc,"Name","TEXT",field_length=50)&lt;/LI-CODE&gt;&lt;P&gt;This code is going to add the attribute "Name" to every feature class in the data frame.&lt;/P&gt;</description>
      <pubDate>Thu, 31 Mar 2022 10:00:02 GMT</pubDate>
      <guid>https://community.esri.com/t5/python-questions/why-addfield-script-always-close-the-application/m-p/1159801#M64239</guid>
      <dc:creator>KimberlyGarbade</dc:creator>
      <dc:date>2022-03-31T10:00:02Z</dc:date>
    </item>
    <item>
      <title>Re: Why AddField script always close the application?</title>
      <link>https://community.esri.com/t5/python-questions/why-addfield-script-always-close-the-application/m-p/1160164#M64242</link>
      <description>&lt;P&gt;Dear Kim,&lt;/P&gt;&lt;P&gt;Yes, That's true, after I am looking back at my ArcMap version, I am currently using an old version, and that script will work for at least 10.6 version, Thanks &lt;span class="lia-unicode-emoji" title=":slightly_smiling_face:"&gt;🙂&lt;/span&gt;&lt;/P&gt;</description>
      <pubDate>Fri, 01 Apr 2022 02:28:15 GMT</pubDate>
      <guid>https://community.esri.com/t5/python-questions/why-addfield-script-always-close-the-application/m-p/1160164#M64242</guid>
      <dc:creator>TessaKhairaniErmanto</dc:creator>
      <dc:date>2022-04-01T02:28:15Z</dc:date>
    </item>
  </channel>
</rss>

