<?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: Input field names with dynamic text box and delete unwanted fields in Python Questions</title>
    <link>https://community.esri.com/t5/python-questions/input-field-names-with-dynamic-text-box-and-delete/m-p/481712#M37671</link>
    <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;SPAN&gt;EDITED:&lt;/SPAN&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;SPAN&gt;I managed to figure this out... My code now iterates through feature classes, requests a field name, calculates fields, deletes unwanted fields. And then joins the left over fields to each other with a spatial join. I was stuck on adding the interactive tkinter dialog box in the first loop, and the delete field text at the end of the first loop. I still have some to do on this, but thought I'd post the answers to my original question. Thought I'd put my code up for others:&lt;/SPAN&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;PRE class="plain" name="code"&gt;import Tkinter import tkSimpleDialog import arcpy from arcpy import env&amp;nbsp; env.workspace = r'G:\TEST\Python_Test\Test.gdb\env'&amp;nbsp; fcList = arcpy.ListFeatureClasses()&amp;nbsp; for fc in fcList: &amp;nbsp;&amp;nbsp;&amp;nbsp; print fc &amp;nbsp;&amp;nbsp;&amp;nbsp; root = Tkinter.Tk() &amp;nbsp;&amp;nbsp;&amp;nbsp; var = tkSimpleDialog.askstring("Field Name", "Enter Field Name") &amp;nbsp;&amp;nbsp;&amp;nbsp; print var&amp;nbsp; &amp;nbsp;&amp;nbsp;&amp;nbsp; arcpy.AddField_management(fc, var, "TEXT", "", "", "50", "", "NULLABLE", "REQUIRED", "") &amp;nbsp;&amp;nbsp;&amp;nbsp; print "Adding field name " + var + " to " + fc &amp;nbsp;&amp;nbsp;&amp;nbsp; arcpy.CalculateField_management(fc, var, "\"Y\"", "PYTHON", "") &amp;nbsp;&amp;nbsp;&amp;nbsp; print "Calculating field " + var + " to " + fc&amp;nbsp; &amp;nbsp;&amp;nbsp;&amp;nbsp; keep = ['OBJECTID', 'Shape', 'Tower', var, 'Shape_Area', 'Shape_Length']&amp;nbsp; &amp;nbsp;&amp;nbsp;&amp;nbsp; discard = [] &amp;nbsp;&amp;nbsp;&amp;nbsp; for field in [f.name for f in arcpy.ListFields(fc)if f.type &amp;lt;&amp;gt; 'OBJECTID']: &amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; if field not in keep: &amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; discard.append(field) &amp;nbsp;&amp;nbsp;&amp;nbsp; arcpy.DeleteField_management(fc, discard) &amp;nbsp;&amp;nbsp;&amp;nbsp; print "Deleted all fields except those specified"&amp;nbsp; # Input variables for spatial join Buffer1 = r'G:\Test\Python_Test\Test.gdb\Buffer1' Buffer2 = r'G:\Test\Python_Test\Test.gdb\Buffer2'&amp;nbsp; sjList = arcpy.ListFeatureClasses()&amp;nbsp; # For loop for spatial join process&amp;nbsp; for sj in sjList:&amp;nbsp; &amp;nbsp;&amp;nbsp;&amp;nbsp; # Spatial join between buffered points and feature &amp;nbsp;&amp;nbsp;&amp;nbsp; arcpy.SpatialJoin_analysis(Buffer1, sj, Buffer2, "JOIN_ONE_TO_ONE", "KEEP_ALL") &amp;nbsp;&amp;nbsp;&amp;nbsp; print "Completed spatial join " + sj&amp;nbsp; &amp;nbsp;&amp;nbsp;&amp;nbsp; # Delete Buffer1 containing no joined features &amp;nbsp;&amp;nbsp;&amp;nbsp; arcpy.Delete_management(Buffer1, "FeatureClass") &amp;nbsp;&amp;nbsp;&amp;nbsp; print "deleted Buffer1 " + sj&amp;nbsp; &amp;nbsp;&amp;nbsp;&amp;nbsp; # Copies Buffer2 containing joined features and outputs as Buffer1 &amp;nbsp;&amp;nbsp;&amp;nbsp; arcpy.Copy_management(Buffer2, Buffer1, "") &amp;nbsp;&amp;nbsp;&amp;nbsp; print "Copied Buffer2 to Buffer1 "&amp;nbsp; + sj&amp;nbsp; &amp;nbsp;&amp;nbsp;&amp;nbsp; # Deletes Buffer2 to allow script to create Buffer2 in next iteration &amp;nbsp;&amp;nbsp;&amp;nbsp; arcpy.Delete_management(Buffer2, "FeatureClass") &amp;nbsp;&amp;nbsp;&amp;nbsp; print "Deleted Buffer2 "&amp;nbsp; + sj&lt;/PRE&gt;&lt;DIV style="display:none;"&gt; &lt;/DIV&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
    <pubDate>Sun, 28 Apr 2013 15:27:45 GMT</pubDate>
    <dc:creator>SamCoggins1</dc:creator>
    <dc:date>2013-04-28T15:27:45Z</dc:date>
    <item>
      <title>Input field names with dynamic text box and delete unwanted fields</title>
      <link>https://community.esri.com/t5/python-questions/input-field-names-with-dynamic-text-box-and-delete/m-p/481711#M37670</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;SPAN&gt;Hi all&lt;/SPAN&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;SPAN&gt;I'm trying to find a way to add field names to each feature class in a geodatabase with Python. &lt;/SPAN&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;SPAN&gt;My pseudo-code so far is:&lt;/SPAN&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;SPAN&gt;1) Buffer points&lt;/SPAN&gt;&lt;BR /&gt;&lt;SPAN&gt;2) Add field to each featureclass with name that represents the featureclass.&lt;/SPAN&gt;&lt;BR /&gt;&lt;SPAN&gt;3) Calculate field, entering the value Y in each field.&lt;/SPAN&gt;&lt;BR /&gt;&lt;SPAN&gt;4) Perform Spatial join on, the Y value will appear in each record where the point intersects featureclasses.&lt;/SPAN&gt;&lt;BR /&gt;&lt;SPAN&gt;5) Delete all unwanted fields so that I am left with the point identifier, and each column containing Y's&lt;/SPAN&gt;&lt;BR /&gt;&lt;SPAN&gt;6) Output to .csv&lt;/SPAN&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;SPAN&gt;I can do the spatial join and have that running. At the moment I have no way of determining the unique field name for each featureclass. &lt;/SPAN&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;SPAN&gt;So I would like the field names to be meaningful, (not just Field1). I am using about 40 features which represent a variety of environmental considerations. For example, for a file representing wetlands I would like a field called Wetland. I have looked at TKInter which I've read can be used to enter text dynamically and then used as a variable, which I think would work well. It would ensure that I know what each field name means. I just don't seem to be able to use the input text as a variable. &lt;/SPAN&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;SPAN&gt;The TKInter code is (I am open to other suggestions of course):&lt;/SPAN&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;PRE class="plain" name="code"&gt;import arcpy from arcpy import env from Tkinter import *&amp;nbsp; # Environment Workspace env.workspace = r'G:\TEST\Python_Test\Test.gdb'&amp;nbsp; def receive(): &amp;nbsp;&amp;nbsp;&amp;nbsp; text = E1.get() &amp;nbsp;&amp;nbsp;&amp;nbsp; print (text) top = Tk() L1 = Label(top, text="User Name") L1.pack( side = LEFT) E1 = Entry(top, bd =5) E1.pack(side = RIGHT) b = Button(top, text="OK", width=10, command=receive) b.pack() top.mainloop()&lt;/PRE&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;SPAN&gt;My code so far is:&lt;/SPAN&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;PRE class="plain" name="code"&gt; # Import arcpy module import arcpy from arcpy import env&amp;nbsp; env.workspace = r'G:\Test\Python_Test\Test.gdb\env'&amp;nbsp; # Local variables: Buffer1 = r'G:\Test\Python_Test\Test.gdb\Buffer1' Buffer2 = r'G:\Test\Python_Test\Test.gdb\Buffer2'&amp;nbsp; # Add and calculate fields (WOULD BE NICE TO REPLACE THIS SECTION WITH TKinter CODE) inFile1 = 'Env_consideration1' arcpy.AddField_management(inFile1, "RVMA", "TEXT", "", "", "50", "", "NULLABLE", "REQUIRED", "") print inFile1 + " Added field" arcpy.CalculateField_management(inFile1, "RVMA", "\"Y\"", "PYTHON", "") print inFile1 + " Calculating field"&amp;nbsp; inFile2 = 'Env_consideration2' arcpy.AddField_management(inFile2, "GWR", "TEXT", "", "", "50", "", "NULLABLE", "REQUIRED", "") print inFile2 + " Added field" arcpy.CalculateField_management(inFile2, "GWR", "\"Y\"", "PYTHON", "") print inFile2 + " Calculating field"&amp;nbsp; fcList = arcpy.ListFeatureClasses()&amp;nbsp; for f in fcList: &amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; &amp;nbsp;&amp;nbsp;&amp;nbsp; # Process: Spatial Join &amp;nbsp;&amp;nbsp;&amp;nbsp; arcpy.SpatialJoin_analysis(Buffer1, f, Buffer2, "JOIN_ONE_TO_ONE", "KEEP_ALL") &amp;nbsp;&amp;nbsp;&amp;nbsp; print "Completed spatial join " + f&amp;nbsp; &amp;nbsp;&amp;nbsp;&amp;nbsp; # Process: Delete &amp;nbsp;&amp;nbsp;&amp;nbsp; arcpy.Delete_management(Buffer1, "FeatureClass") &amp;nbsp;&amp;nbsp;&amp;nbsp; print "deleted Buffer1 " + f&amp;nbsp; &amp;nbsp;&amp;nbsp;&amp;nbsp; # Process: Copy &amp;nbsp;&amp;nbsp;&amp;nbsp; arcpy.Copy_management(Buffer2, Buffer1, "") &amp;nbsp;&amp;nbsp;&amp;nbsp; print "Copied Buffer2 to Buffer1 "&amp;nbsp; + f&amp;nbsp; &amp;nbsp;&amp;nbsp;&amp;nbsp; # Process: Delete &amp;nbsp;&amp;nbsp;&amp;nbsp; arcpy.Delete_management(Buffer2, "FeatureClass") &amp;nbsp;&amp;nbsp;&amp;nbsp; print "Deleted Buffer2 "&amp;nbsp; + f&amp;nbsp; keep = ['OBJECTID', 'Shape', 'Tower', 'RVMA','GWR', 'Shape_Area', 'Shape_Length']&amp;nbsp; discard = [] for field in [f.name for f in arcpy.ListFields(Buffer1)if f.type &amp;lt;&amp;gt; 'OBJECTID']: &amp;nbsp;&amp;nbsp;&amp;nbsp; if field not in keep: &amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; discard.append(field) arcpy.DeleteField_management(Buffer1, discard) &lt;/PRE&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Sat, 27 Apr 2013 18:33:05 GMT</pubDate>
      <guid>https://community.esri.com/t5/python-questions/input-field-names-with-dynamic-text-box-and-delete/m-p/481711#M37670</guid>
      <dc:creator>SamCoggins1</dc:creator>
      <dc:date>2013-04-27T18:33:05Z</dc:date>
    </item>
    <item>
      <title>Re: Input field names with dynamic text box and delete unwanted fields</title>
      <link>https://community.esri.com/t5/python-questions/input-field-names-with-dynamic-text-box-and-delete/m-p/481712#M37671</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;SPAN&gt;EDITED:&lt;/SPAN&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;SPAN&gt;I managed to figure this out... My code now iterates through feature classes, requests a field name, calculates fields, deletes unwanted fields. And then joins the left over fields to each other with a spatial join. I was stuck on adding the interactive tkinter dialog box in the first loop, and the delete field text at the end of the first loop. I still have some to do on this, but thought I'd post the answers to my original question. Thought I'd put my code up for others:&lt;/SPAN&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;PRE class="plain" name="code"&gt;import Tkinter import tkSimpleDialog import arcpy from arcpy import env&amp;nbsp; env.workspace = r'G:\TEST\Python_Test\Test.gdb\env'&amp;nbsp; fcList = arcpy.ListFeatureClasses()&amp;nbsp; for fc in fcList: &amp;nbsp;&amp;nbsp;&amp;nbsp; print fc &amp;nbsp;&amp;nbsp;&amp;nbsp; root = Tkinter.Tk() &amp;nbsp;&amp;nbsp;&amp;nbsp; var = tkSimpleDialog.askstring("Field Name", "Enter Field Name") &amp;nbsp;&amp;nbsp;&amp;nbsp; print var&amp;nbsp; &amp;nbsp;&amp;nbsp;&amp;nbsp; arcpy.AddField_management(fc, var, "TEXT", "", "", "50", "", "NULLABLE", "REQUIRED", "") &amp;nbsp;&amp;nbsp;&amp;nbsp; print "Adding field name " + var + " to " + fc &amp;nbsp;&amp;nbsp;&amp;nbsp; arcpy.CalculateField_management(fc, var, "\"Y\"", "PYTHON", "") &amp;nbsp;&amp;nbsp;&amp;nbsp; print "Calculating field " + var + " to " + fc&amp;nbsp; &amp;nbsp;&amp;nbsp;&amp;nbsp; keep = ['OBJECTID', 'Shape', 'Tower', var, 'Shape_Area', 'Shape_Length']&amp;nbsp; &amp;nbsp;&amp;nbsp;&amp;nbsp; discard = [] &amp;nbsp;&amp;nbsp;&amp;nbsp; for field in [f.name for f in arcpy.ListFields(fc)if f.type &amp;lt;&amp;gt; 'OBJECTID']: &amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; if field not in keep: &amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; discard.append(field) &amp;nbsp;&amp;nbsp;&amp;nbsp; arcpy.DeleteField_management(fc, discard) &amp;nbsp;&amp;nbsp;&amp;nbsp; print "Deleted all fields except those specified"&amp;nbsp; # Input variables for spatial join Buffer1 = r'G:\Test\Python_Test\Test.gdb\Buffer1' Buffer2 = r'G:\Test\Python_Test\Test.gdb\Buffer2'&amp;nbsp; sjList = arcpy.ListFeatureClasses()&amp;nbsp; # For loop for spatial join process&amp;nbsp; for sj in sjList:&amp;nbsp; &amp;nbsp;&amp;nbsp;&amp;nbsp; # Spatial join between buffered points and feature &amp;nbsp;&amp;nbsp;&amp;nbsp; arcpy.SpatialJoin_analysis(Buffer1, sj, Buffer2, "JOIN_ONE_TO_ONE", "KEEP_ALL") &amp;nbsp;&amp;nbsp;&amp;nbsp; print "Completed spatial join " + sj&amp;nbsp; &amp;nbsp;&amp;nbsp;&amp;nbsp; # Delete Buffer1 containing no joined features &amp;nbsp;&amp;nbsp;&amp;nbsp; arcpy.Delete_management(Buffer1, "FeatureClass") &amp;nbsp;&amp;nbsp;&amp;nbsp; print "deleted Buffer1 " + sj&amp;nbsp; &amp;nbsp;&amp;nbsp;&amp;nbsp; # Copies Buffer2 containing joined features and outputs as Buffer1 &amp;nbsp;&amp;nbsp;&amp;nbsp; arcpy.Copy_management(Buffer2, Buffer1, "") &amp;nbsp;&amp;nbsp;&amp;nbsp; print "Copied Buffer2 to Buffer1 "&amp;nbsp; + sj&amp;nbsp; &amp;nbsp;&amp;nbsp;&amp;nbsp; # Deletes Buffer2 to allow script to create Buffer2 in next iteration &amp;nbsp;&amp;nbsp;&amp;nbsp; arcpy.Delete_management(Buffer2, "FeatureClass") &amp;nbsp;&amp;nbsp;&amp;nbsp; print "Deleted Buffer2 "&amp;nbsp; + sj&lt;/PRE&gt;&lt;DIV style="display:none;"&gt; &lt;/DIV&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Sun, 28 Apr 2013 15:27:45 GMT</pubDate>
      <guid>https://community.esri.com/t5/python-questions/input-field-names-with-dynamic-text-box-and-delete/m-p/481712#M37671</guid>
      <dc:creator>SamCoggins1</dc:creator>
      <dc:date>2013-04-28T15:27:45Z</dc:date>
    </item>
  </channel>
</rss>

