<?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: Add Field then Set the Field Value? in Python Questions</title>
    <link>https://community.esri.com/t5/python-questions/add-field-then-set-the-field-value/m-p/171251#M13161</link>
    <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;SPAN&gt;Thanks!&lt;/SPAN&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;SPAN&gt;This is pretty much exactly what I had, except the parameters are text. int() is for integer is it not?&lt;/SPAN&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;SPAN&gt;No matter what I seem to have used, the values stay at &amp;lt;Null&amp;gt;&lt;/SPAN&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;SPAN&gt;The nice thing is that this confirms that I was on the right track. I'm looking through python string functions as we speak. &lt;/SPAN&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;SPAN&gt;Cheers!&lt;/SPAN&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
    <pubDate>Tue, 31 Jul 2012 14:53:25 GMT</pubDate>
    <dc:creator>RobertStewart</dc:creator>
    <dc:date>2012-07-31T14:53:25Z</dc:date>
    <item>
      <title>Add Field then Set the Field Value?</title>
      <link>https://community.esri.com/t5/python-questions/add-field-then-set-the-field-value/m-p/171249#M13159</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;SPAN&gt;I have a python script in which the end result is a single polygon in a file geodatabase that is added to the current map view. That part works fine. &lt;/SPAN&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;SPAN&gt;What I want to do is create 2 new fields and set the values in those fields to be two parameters set in the original run of the tool (getparametersastext). &lt;/SPAN&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;SPAN&gt;For example, would like to create two new fields: ZFile and Planner&lt;/SPAN&gt;&lt;BR /&gt;&lt;SPAN&gt;Then set those fields to be equal to the parameters set manually at the start of the tool: Zfile and Planner&lt;/SPAN&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;SPAN&gt;I've successfully created the fields, but I've had no success at setting the values for either.&lt;/SPAN&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;SPAN&gt;As I mentioned, there is only one row in the dataset. I can set it manually, but the idea is to automate all of this. &lt;/SPAN&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;SPAN&gt;Any points in the right direction are gratefully accepted. &lt;/SPAN&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;SPAN&gt;Cheers!&lt;/SPAN&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Mon, 30 Jul 2012 18:20:07 GMT</pubDate>
      <guid>https://community.esri.com/t5/python-questions/add-field-then-set-the-field-value/m-p/171249#M13159</guid>
      <dc:creator>RobertStewart</dc:creator>
      <dc:date>2012-07-30T18:20:07Z</dc:date>
    </item>
    <item>
      <title>Re: Add Field then Set the Field Value?</title>
      <link>https://community.esri.com/t5/python-questions/add-field-then-set-the-field-value/m-p/171250#M13160</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;SPAN&gt;It'd look something like this:&lt;/SPAN&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;PRE class="lia-code-sample line-numbers language-none"&gt;myFC = arcpy.GetParameterAsText(0)
var1 = arcpy.GetParameterAsText(1)
var2 = arcpy.GetParameterAsText(2)
arcpy.AddField_management(myFC, "FIELD1", "SHORT")
arcpy.AddField_management(myFC, "FIELD2", "SHORT")
arcpy.CalculateField_managment(myFC, "FIELD1", int(var1), "PYTHON")
arcpy.CalculateField_managment(myFC, "FIELD2", int(var2), "PYTHON")&lt;/PRE&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Sat, 11 Dec 2021 08:52:31 GMT</pubDate>
      <guid>https://community.esri.com/t5/python-questions/add-field-then-set-the-field-value/m-p/171250#M13160</guid>
      <dc:creator>ChrisSnyder</dc:creator>
      <dc:date>2021-12-11T08:52:31Z</dc:date>
    </item>
    <item>
      <title>Re: Add Field then Set the Field Value?</title>
      <link>https://community.esri.com/t5/python-questions/add-field-then-set-the-field-value/m-p/171251#M13161</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;SPAN&gt;Thanks!&lt;/SPAN&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;SPAN&gt;This is pretty much exactly what I had, except the parameters are text. int() is for integer is it not?&lt;/SPAN&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;SPAN&gt;No matter what I seem to have used, the values stay at &amp;lt;Null&amp;gt;&lt;/SPAN&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;SPAN&gt;The nice thing is that this confirms that I was on the right track. I'm looking through python string functions as we speak. &lt;/SPAN&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;SPAN&gt;Cheers!&lt;/SPAN&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Tue, 31 Jul 2012 14:53:25 GMT</pubDate>
      <guid>https://community.esri.com/t5/python-questions/add-field-then-set-the-field-value/m-p/171251#M13161</guid>
      <dc:creator>RobertStewart</dc:creator>
      <dc:date>2012-07-31T14:53:25Z</dc:date>
    </item>
    <item>
      <title>Re: Add Field then Set the Field Value?</title>
      <link>https://community.esri.com/t5/python-questions/add-field-then-set-the-field-value/m-p/171252#M13162</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;SPAN&gt;As the name implies the arcpy.GetParameterAsText() method always brings values from the toolbox GUI into the script as string values. Three Python functions I use all the time:&lt;/SPAN&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;SPAN&gt;convert to interger: int(myVariable)&lt;/SPAN&gt;&lt;BR /&gt;&lt;SPAN&gt;convert to float: float(myVariable)&lt;/SPAN&gt;&lt;BR /&gt;&lt;SPAN&gt;convert to string: str(myVariable)&lt;/SPAN&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;SPAN&gt;Variables must be of the same type to do math operations or string concatenation. For example:&lt;/SPAN&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;PRE class="lia-code-sample line-numbers language-none"&gt;buffDist = arcpy.GetParameterAsText(0)
newBuffDist = float(buffDist) / 3.14159
arcpy.Buffer_analysis(myFC, myBuffFC, str(newBuffDist) + " METERS")&lt;/PRE&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Sat, 11 Dec 2021 08:52:33 GMT</pubDate>
      <guid>https://community.esri.com/t5/python-questions/add-field-then-set-the-field-value/m-p/171252#M13162</guid>
      <dc:creator>ChrisSnyder</dc:creator>
      <dc:date>2021-12-11T08:52:33Z</dc:date>
    </item>
    <item>
      <title>Re: Add Field then Set the Field Value?</title>
      <link>https://community.esri.com/t5/python-questions/add-field-then-set-the-field-value/m-p/171253#M13163</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;SPAN&gt;Wow, when trying to self-teach, the simplest things escape me. &lt;/SPAN&gt;&lt;BR /&gt;&lt;SPAN&gt;I will be keeping those notes close at hand, we do a lot of that here. Thanks for that!&lt;/SPAN&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;SPAN&gt;However, I still seem to be getting errors. Let me write out the variables and maybe this will be more clear:&lt;/SPAN&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;SPAN&gt;ZFile = arcpy.GetParameterAsText(0)&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; - Entered in the toolbox as: "Z-12-1234"&lt;/SPAN&gt;&lt;BR /&gt;&lt;SPAN&gt;Planner = arcpy.GetParameterAsText(1)&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; - Entered into the toolbox as: "XX"&lt;/SPAN&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;SPAN&gt;I want to pass these values into a featureclass that was created via the same script, into a field called: "ZFile" and "Planner" (respectively). &lt;/SPAN&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;SPAN&gt;arcpy.CalculateField_management("MyFC","ZFile",int(ZFile),"PYTHON")&lt;/SPAN&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;SPAN&gt;The int(Zfile) expression returns an invalid literal. I'm too new at this to understand what that means.&lt;/SPAN&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;SPAN&gt;I 'do' appreciate the help on this. I think I'm awfully close to the end.....&lt;/SPAN&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Tue, 31 Jul 2012 15:44:09 GMT</pubDate>
      <guid>https://community.esri.com/t5/python-questions/add-field-then-set-the-field-value/m-p/171253#M13163</guid>
      <dc:creator>RobertStewart</dc:creator>
      <dc:date>2012-07-31T15:44:09Z</dc:date>
    </item>
    <item>
      <title>Re: Add Field then Set the Field Value?</title>
      <link>https://community.esri.com/t5/python-questions/add-field-then-set-the-field-value/m-p/171254#M13164</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;SPAN&gt;Sorry - leave off the int() part in the CalculateField tool. No sense in converting your character string to an integer! I was under the assumption your input values were integers. Not sure why I was thinking that...&lt;/SPAN&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;SPAN&gt;This should work:&lt;/SPAN&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;PRE class="lia-code-sample line-numbers language-none"&gt;myFC = arcpy.GetParameterAsText(0)
var1 = arcpy.GetParameterAsText(1)
var2 = arcpy.GetParameterAsText(2)
arcpy.AddField_management(myFC, "FIELD1", "SHORT")
arcpy.AddField_management(myFC, "FIELD2", "SHORT")
arcpy.CalculateField_managment(myFC, "FIELD1", "'" + var1 + "'", "PYTHON")
arcpy.CalculateField_managment(myFC, "FIELD2", "'" + var2 + "'", "PYTHON")&lt;/PRE&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Sat, 11 Dec 2021 08:52:37 GMT</pubDate>
      <guid>https://community.esri.com/t5/python-questions/add-field-then-set-the-field-value/m-p/171254#M13164</guid>
      <dc:creator>ChrisSnyder</dc:creator>
      <dc:date>2021-12-11T08:52:37Z</dc:date>
    </item>
    <item>
      <title>Re: Add Field then Set the Field Value?</title>
      <link>https://community.esri.com/t5/python-questions/add-field-then-set-the-field-value/m-p/171255#M13165</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;SPAN&gt;Hmmm. Still not working. Posted below is my code. I feel like this should have worked. I had forgotten about the quotes within quotes bit.&lt;/SPAN&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;SPAN&gt;In modelbuilder, I was forced to use '%Variable%'. Could that be it? (yes, I'm going to have a go at it...)&lt;/SPAN&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;SPAN&gt;I did try setting the field type alternatively to "SHORT" and "TEXT", but neither made a difference. The fields get created but not populated. &lt;/SPAN&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;SPAN&gt;Zfile and Planner variables are set by the tool GUI. &lt;/SPAN&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;SPAN&gt;I feel like trying to create a fully automated, fully dynamic script was maybe NOT the best idea for my first delve into python....&lt;/SPAN&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;SPAN&gt;----&lt;/SPAN&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;SPAN&gt; df = arcpy.mapping.ListDataFrames(mxd, "PLOCMain")[0]&lt;/SPAN&gt;&lt;BR /&gt;&lt;SPAN&gt; addLayer = arcpy.mapping.Layer(SaveFile)&lt;/SPAN&gt;&lt;BR /&gt;&lt;SPAN&gt; arcpy.mapping.AddLayer(df, addLayer, "TOP")&lt;/SPAN&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;SPAN&gt; arcpy.AddField_management(addLayer,"ZFile","TEXT")&lt;/SPAN&gt;&lt;BR /&gt;&lt;SPAN&gt; arcpy.AddField_management(addLayer, "Planner","TEXT")&lt;/SPAN&gt;&lt;BR /&gt;&lt;SPAN&gt;&amp;nbsp; &lt;/SPAN&gt;&lt;BR /&gt;&lt;SPAN&gt; arcpy.CalculateField_managment(addLayer, "ZFile", "'" + ZFile + "'", "PYTHON")&lt;/SPAN&gt;&lt;BR /&gt;&lt;SPAN&gt; arcpy.CalculateField_managment(addLayer, "Planner", "'" + Planner + "'", "PYTHON")&lt;/SPAN&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Tue, 31 Jul 2012 18:11:29 GMT</pubDate>
      <guid>https://community.esri.com/t5/python-questions/add-field-then-set-the-field-value/m-p/171255#M13165</guid>
      <dc:creator>RobertStewart</dc:creator>
      <dc:date>2012-07-31T18:11:29Z</dc:date>
    </item>
    <item>
      <title>Re: Add Field then Set the Field Value?</title>
      <link>https://community.esri.com/t5/python-questions/add-field-then-set-the-field-value/m-p/171256#M13166</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;SPAN&gt;.....&lt;/SPAN&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;SPAN&gt;And now I 'fully' realize why copying and pasting script is a better idea than writing my own....&lt;/SPAN&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;SPAN&gt;arcpy.CalculateField_managEment()......&lt;/SPAN&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;SPAN&gt;Sigh. &lt;/SPAN&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;SPAN&gt;The last (corrected) script now produces blank fields as opposed to &amp;lt;Null&amp;gt;. I consider that a sign of improvement.&lt;/SPAN&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Tue, 31 Jul 2012 19:02:23 GMT</pubDate>
      <guid>https://community.esri.com/t5/python-questions/add-field-then-set-the-field-value/m-p/171256#M13166</guid>
      <dc:creator>RobertStewart</dc:creator>
      <dc:date>2012-07-31T19:02:23Z</dc:date>
    </item>
    <item>
      <title>Re: Add Field then Set the Field Value?</title>
      <link>https://community.esri.com/t5/python-questions/add-field-then-set-the-field-value/m-p/171257#M13167</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;SPAN&gt;Yes, it'd be good to change the field types to text...&lt;/SPAN&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;SPAN&gt;How about this:&lt;/SPAN&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;PRE class="plain" name="code"&gt;myFC = arcpy.GetParameterAsText(0) var1 = arcpy.GetParameterAsText(1) var2 = arcpy.GetParameterAsText(2) arcpy.AddField_management(myFC, "FIELD1", "TEXT", "", "", "50") arcpy.AddField_management(myFC, "FIELD2", "TEXT", "", "", "50") arcpy.CalculateField_managment(myFC, "FIELD1", "'" + var1 + "'", "PYTHON") arcpy.CalculateField_managment(myFC, "FIELD2", "'" + var2 + "'", "PYTHON")&lt;/PRE&gt;&lt;DIV style="display:none;"&gt; &lt;/DIV&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;SPAN&gt;an alternate way using an update cursor:&lt;/SPAN&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;PRE class="plain" name="code"&gt;myFC = arcpy.GetParameterAsText(0) var1 = arcpy.GetParameterAsText(1) var2 = arcpy.GetParameterAsText(2) arcpy.AddField_management(myFC, "FIELD1", "TEXT", "", "", "50") arcpy.AddField_management(myFC, "FIELD2", "TEXT", "", "", "50") updateRows = arcpy.UpdateCursor(myFC) for updateRow in updateRows: &amp;nbsp;&amp;nbsp;&amp;nbsp; updateRow.FIELD1 = var1 &amp;nbsp;&amp;nbsp;&amp;nbsp; updateRow.FIELD2 = var2 &amp;nbsp;&amp;nbsp;&amp;nbsp; updateRows.updateRow(updateRow) del updateRow, updateRows&lt;/PRE&gt;&lt;DIV style="display:none;"&gt; &lt;/DIV&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;SPAN&gt;If this aint working.... I dunno...&lt;/SPAN&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;SPAN&gt;Are you sure your toolbox script tool is pointing to the correct script?&lt;/SPAN&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Tue, 31 Jul 2012 22:01:12 GMT</pubDate>
      <guid>https://community.esri.com/t5/python-questions/add-field-then-set-the-field-value/m-p/171257#M13167</guid>
      <dc:creator>ChrisSnyder</dc:creator>
      <dc:date>2012-07-31T22:01:12Z</dc:date>
    </item>
    <item>
      <title>Re: Add Field then Set the Field Value?</title>
      <link>https://community.esri.com/t5/python-questions/add-field-then-set-the-field-value/m-p/171258#M13168</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;SPAN&gt;Indeed a good question, but yes, it is pointed correctly. &lt;/SPAN&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;SPAN&gt;The script runs perfectly now, if I copy and paste it into a python window in ArcMap. This means I need to set the variables in the script instead of by the GUI. &lt;/SPAN&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;SPAN&gt;Through the GUI/Toolbox, however, nothing seems to want to make the fields populate (they are blank instead of &amp;lt;Null&amp;gt;).&lt;/SPAN&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;SPAN&gt;I sincerely thank you for helping me with this. For the sake of sanity, I may try simply have to manually enter those values into each map. Not the end of the world. &lt;/SPAN&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;SPAN&gt;Cheers!&lt;/SPAN&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Wed, 01 Aug 2012 13:19:12 GMT</pubDate>
      <guid>https://community.esri.com/t5/python-questions/add-field-then-set-the-field-value/m-p/171258#M13168</guid>
      <dc:creator>RobertStewart</dc:creator>
      <dc:date>2012-08-01T13:19:12Z</dc:date>
    </item>
    <item>
      <title>Re: Add Field then Set the Field Value?</title>
      <link>https://community.esri.com/t5/python-questions/add-field-then-set-the-field-value/m-p/171259#M13169</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;SPAN&gt;Okay one last stab... Note the #comments...&lt;/SPAN&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;PRE class="lia-code-sample line-numbers language-none"&gt;import arcpy
arcpy.SetProduct("ArcInfo") #or whatever lic level you are using
myFC = arcpy.GetParameterAsText(0) #IMPORTANT: In the toolbox GUI, this parameter should be a type of 'FeatureLayer'
var1 = arcpy.GetParameterAsText(1) #Toolbox type of 'String'
var2 = arcpy.GetParameterAsText(2) #Toolbox type of 'String'
arcpy.AddField_management(myFC, "FIELD1", "TEXT", "", "", "50")
arcpy.AddField_management(myFC, "FIELD2", "TEXT", "", "", "50")
updateRows = arcpy.UpdateCursor(myFC)
for updateRow in updateRows:
&amp;nbsp;&amp;nbsp;&amp;nbsp; updateRow.FIELD1 = var1
&amp;nbsp;&amp;nbsp;&amp;nbsp; updateRow.FIELD2 = var2
&amp;nbsp;&amp;nbsp;&amp;nbsp; updateRows.updateRow(updateRow)
del updateRow, updateRows&lt;/PRE&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Sat, 11 Dec 2021 08:52:39 GMT</pubDate>
      <guid>https://community.esri.com/t5/python-questions/add-field-then-set-the-field-value/m-p/171259#M13169</guid>
      <dc:creator>ChrisSnyder</dc:creator>
      <dc:date>2021-12-11T08:52:39Z</dc:date>
    </item>
    <item>
      <title>Re: Add Field then Set the Field Value?</title>
      <link>https://community.esri.com/t5/python-questions/add-field-then-set-the-field-value/m-p/171260#M13170</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;SPAN&gt;I double checked what the Toolbox variables were set at, and they seem to be correct. However, it did make me think that perhaps I'm doing something wrong somewhere else that's causing this to fail. &lt;/SPAN&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;SPAN&gt;The code works 'except' that last copy of the data into the fields. And that, after all this, is minor. Feel free to point out the mistakes etc if you feel like it, critical advice is always welcome. It's my first real attempt at python. &lt;/SPAN&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;SPAN&gt;Thanks for all your help. I wouldn't have gotten as far as I did without your help. &lt;/SPAN&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;SPAN&gt;Cheers!&lt;/SPAN&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;PRE class="lia-code-sample line-numbers language-none"&gt;
import arcpy,
from arcpy import env
arcpy.SetProduct("ArcInfo")
#Setting the workspace
arcpy.env.workspace = "I:\GIS\Mapping_GIS.gdb"
try:
&amp;nbsp;&amp;nbsp;&amp;nbsp; # Overwrite pre-existing files
&amp;nbsp;&amp;nbsp;&amp;nbsp; arcpy.env.overwriteOutput = True

&amp;nbsp;&amp;nbsp;&amp;nbsp; # Get the input values from the toolbox
&amp;nbsp;&amp;nbsp;&amp;nbsp; strtnum = arcpy.GetParameterAsText(0)#street number
&amp;nbsp;&amp;nbsp;&amp;nbsp; strtnam = arcpy.GetParameterAsText(1)#street name
&amp;nbsp;&amp;nbsp;&amp;nbsp; ZFile = arcpy.GetParameterAsText(2)#This is a file number like Z-00-0000
&amp;nbsp;&amp;nbsp;&amp;nbsp; Planner = arcpy.GetParameterAsText(3) #Usually initials
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; 
&amp;nbsp;&amp;nbsp;&amp;nbsp; FileName = strtnam + "_" + strtnum
&amp;nbsp;&amp;nbsp;&amp;nbsp; SaveFile = "I:\\GIS\\Mapping_GIS.gdb\\" + FileName

&amp;nbsp;&amp;nbsp;&amp;nbsp; ParcelTempLayer = "I:\\GIS\\Mapping_GIS.gdb\\ParcelTempLayer"
&amp;nbsp;&amp;nbsp;&amp;nbsp; AMANDA_PROPERTY = "Database Connections\\Amanda Connection to pama.sde\\AMANDA.PROPERTY"
&amp;nbsp;&amp;nbsp;&amp;nbsp; SDE_Parcels = "Database Connections\\Planning Connection to ctbgis.sde\\SDE.Planning\\SDE.Parcels"

&amp;nbsp;&amp;nbsp;&amp;nbsp; print "variables set"

&amp;nbsp;&amp;nbsp;&amp;nbsp; #Sets the map document to be the current one open
&amp;nbsp;&amp;nbsp;&amp;nbsp; mxd = arcpy.mapping.MapDocument("CURRENT")
&amp;nbsp;&amp;nbsp; 
&amp;nbsp;&amp;nbsp;&amp;nbsp; print "mxd set. Creating ParcelTempLayer - a layer file of SDE_Parcels"

&amp;nbsp;&amp;nbsp;&amp;nbsp; #Makes a layer from the SDE_Parcels data saves it under the parceltemplayer variable
&amp;nbsp;&amp;nbsp;&amp;nbsp; arcpy.MakeFeatureLayer_management(SDE_Parcels, ParcelTempLayer)

&amp;nbsp;&amp;nbsp;&amp;nbsp; print "ParcelTempLayer created. Creating AMANDA TableView"

&amp;nbsp;&amp;nbsp;&amp;nbsp; #Makes a table view from the AMANDA property records
&amp;nbsp;&amp;nbsp;&amp;nbsp; PROPNAM = "PROPNAM"
&amp;nbsp;&amp;nbsp;&amp;nbsp; arcpy.MakeTableView_management(AMANDA_PROPERTY, PROPNAM, "")

&amp;nbsp;&amp;nbsp;&amp;nbsp; print "AMANDA TableView created. Joining Table to Layer"

&amp;nbsp;&amp;nbsp;&amp;nbsp; #Joins the SDE_Parcels and PROPNAM
&amp;nbsp;&amp;nbsp;&amp;nbsp; arcpy.AddJoin_management(ParcelTempLayer, "PCL_PIN", "PROPNAM", "PROPGISID1", "KEEP_COMMON")
&amp;nbsp;&amp;nbsp;&amp;nbsp; print "Joined. Now extracting selection"

&amp;nbsp;&amp;nbsp;&amp;nbsp; expression = "PROPHOUSE = '" + strtnum + "' AND PROPSTREET = '" + strtnam + "'"

&amp;nbsp;&amp;nbsp;&amp;nbsp; #selects data

&amp;nbsp;&amp;nbsp;&amp;nbsp; print "Using this: " + expression

&amp;nbsp;&amp;nbsp;&amp;nbsp; arcpy.Select_analysis(ParcelTempLayer, SaveFile, expression)

&amp;nbsp;&amp;nbsp;&amp;nbsp; df = arcpy.mapping.ListDataFrames(mxd, "PLOCMain")[0]
&amp;nbsp;&amp;nbsp;&amp;nbsp; addLayer = arcpy.mapping.Layer(SaveFile)
&amp;nbsp;&amp;nbsp;&amp;nbsp; arcpy.mapping.AddLayer(df, addLayer, "TOP")

&amp;nbsp;&amp;nbsp;&amp;nbsp; arcpy.AddField_management(addLayer,"ZFile", "TEXT", "", "", "15")
&amp;nbsp;&amp;nbsp;&amp;nbsp; arcpy.AddField_management(addLayer, "Planner", "TEXT", "", "", "5")

&amp;nbsp;&amp;nbsp;&amp;nbsp; arcpy.CalculateField_management(addLayer, "ZFile", "'" + ZFile + "'", "PYTHON")
&amp;nbsp;&amp;nbsp;&amp;nbsp; arcpy.CalculateField_management(addLayer, "Planner", "'" + Planner + "'", "PYTHON")
&amp;nbsp;&amp;nbsp;&amp;nbsp; 
&amp;nbsp;&amp;nbsp;&amp;nbsp; updateRows = arcpy.UpdateCursor(addLayer)
&amp;nbsp;&amp;nbsp;&amp;nbsp; for updateRow in updateRows:
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; updateRow.ZFile = ZFile
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; updateRow.Planner = Planner
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; updateRows.updateRow(updateRow)
&amp;nbsp;&amp;nbsp;&amp;nbsp; del updateRow, updateRows
&amp;nbsp;&amp;nbsp;&amp;nbsp; del mxd, addLayer

&amp;nbsp;&amp;nbsp;&amp;nbsp; print "Complete"

&amp;nbsp;&amp;nbsp; 
except Exception, e:

&amp;nbsp;&amp;nbsp; import traceback, sys
&amp;nbsp;&amp;nbsp; tb = sys.exc_info()[2]
&amp;nbsp;&amp;nbsp; print "Line %i" % tb.tb_lineno
&amp;nbsp;&amp;nbsp; print e.message

del strtnam
del strtnum
del ZFile
del Planner
del PROPNAM
#del PROPNUM

del ParcelTempLayer
del SaveFile
del FileName
del AMANDA_PROPERTY
del SDE_Parcels
print "variables deleted"


&lt;/PRE&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Sat, 11 Dec 2021 08:52:42 GMT</pubDate>
      <guid>https://community.esri.com/t5/python-questions/add-field-then-set-the-field-value/m-p/171260#M13170</guid>
      <dc:creator>RobertStewart</dc:creator>
      <dc:date>2021-12-11T08:52:42Z</dc:date>
    </item>
    <item>
      <title>Re: Add Field then Set the Field Value?</title>
      <link>https://community.esri.com/t5/python-questions/add-field-then-set-the-field-value/m-p/171261#M13171</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;SPAN&gt;That was confirmed. &lt;/SPAN&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;SPAN&gt;Removing the try/except statements and dedenting it made the script work perfectly (using the updatecursor commands, NOT the calculatefield cammand). &lt;/SPAN&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;SPAN&gt;Cheers!&lt;/SPAN&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Thu, 02 Aug 2012 14:55:01 GMT</pubDate>
      <guid>https://community.esri.com/t5/python-questions/add-field-then-set-the-field-value/m-p/171261#M13171</guid>
      <dc:creator>RobertStewart</dc:creator>
      <dc:date>2012-08-02T14:55:01Z</dc:date>
    </item>
  </channel>
</rss>

