<?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: copyfield based on Cxxxx in Python Questions</title>
    <link>https://community.esri.com/t5/python-questions/copyfield-based-on-cxxxx/m-p/323386#M25184</link>
    <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;SPAN&gt;Didn't even recognize that.&amp;nbsp; Guess I really wasn't trying to pick apart the code, just that I have been "bitten" by describe statements within a loop before, so that really stood out to me.&lt;/SPAN&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;SPAN&gt;R_&lt;/SPAN&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
    <pubDate>Thu, 27 Jun 2013 18:15:57 GMT</pubDate>
    <dc:creator>RhettZufelt</dc:creator>
    <dc:date>2013-06-27T18:15:57Z</dc:date>
    <item>
      <title>copyfield based on Cxxxx</title>
      <link>https://community.esri.com/t5/python-questions/copyfield-based-on-cxxxx/m-p/323380#M25178</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;SPAN&gt;System: Windows Vista and ArcGIS 9.3&lt;/SPAN&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;SPAN&gt;Hello, &lt;/SPAN&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;SPAN&gt;I have 100 shapefiles called geocXXXX.shp (geoc0782, geoc9838, and geoc6728 etc)&lt;/SPAN&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;SPAN&gt;In each shapefile, there is a field call CXXXX (C0782, C9838, and C6728 etc).&lt;/SPAN&gt;&lt;BR /&gt;&lt;SPAN&gt;The field property is string, length =6.&lt;/SPAN&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;SPAN&gt;Now I would like to make a new field call CXXXXD (C0782D, C9838D, and C6728D etc).&lt;/SPAN&gt;&lt;BR /&gt;&lt;SPAN&gt;The field property is long integer, length =9.&lt;/SPAN&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;SPAN&gt;Please kindly advise how to modify the follow code and thank you.&lt;/SPAN&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;PRE class="plain" name="code"&gt;##Script Name: Copy field ##Description: Copy field using CXXXX ##Created By: Elaine Kuo ##Date: 06/25/2013&amp;nbsp;&amp;nbsp; #Import standard library modules import arcgisscripting import os&amp;nbsp; #Create the Geoprocessor object gp = arcgisscripting.create(9.3)&amp;nbsp; #Set the input workspace #GP.workspace = sys.argv[1] #Set the workspace. gp.Workspace= "H:/temp_D/test"&amp;nbsp; #Set the output workspace #outWorkspace = sys.argv[2] #Set the workspace. List all of the feature classes in the dataset outWorkspace= "H:/temp_D"&amp;nbsp; #Get a list of the featureclasses in the input folder fcs = gp.ListFeatureClasses()&amp;nbsp; # Loop through every item in the list that was just generated for fc in fcs:&amp;nbsp; &amp;nbsp;&amp;nbsp;&amp;nbsp; # Break out the name, no path or extension, using the describe object. &amp;nbsp;&amp;nbsp;&amp;nbsp; desc = gp.describe(fc) &amp;nbsp;&amp;nbsp;&amp;nbsp; featureName = desc.name&amp;nbsp; &amp;nbsp;&amp;nbsp;&amp;nbsp; #Validate the new feature class name for the output workspace. &amp;nbsp;&amp;nbsp;&amp;nbsp; OutFeatureClass = outWorkspace + os.sep + gp.ValidateTableName(fc,outWorkspace)&amp;nbsp; &amp;nbsp;&amp;nbsp;&amp;nbsp; #get file name &amp;nbsp;&amp;nbsp;&amp;nbsp; fcName, fcExt = os.path.splitext(fc)&amp;nbsp;&amp;nbsp; &amp;nbsp;&amp;nbsp; &amp;nbsp;&amp;nbsp;&amp;nbsp; #&amp;nbsp;&amp;nbsp; Get a list of the fields in the featureclass &amp;nbsp;&amp;nbsp;&amp;nbsp; fields = gp.listFields(fc, "C*", "String")&amp;nbsp; &amp;nbsp;&amp;nbsp;&amp;nbsp; # replace the strings you want to &amp;nbsp;&amp;nbsp;&amp;nbsp; fcName = fcName.replace("D","") &amp;nbsp;&amp;nbsp;&amp;nbsp; fcName = fcName + fcExt &amp;nbsp;&amp;nbsp;&amp;nbsp; fcName = outWorkspace + os.sep + fcName &amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; &amp;nbsp;&amp;nbsp;&amp;nbsp; #get file name &amp;nbsp;&amp;nbsp;&amp;nbsp; fcName, fcExt = os.path.splitext(fc)&amp;nbsp; &amp;nbsp;&amp;nbsp;&amp;nbsp; fieldName = fcName + "D"&amp;nbsp; #build field name&amp;nbsp; &amp;nbsp;&amp;nbsp;&amp;nbsp; #Add field to each SHP &amp;nbsp;&amp;nbsp;&amp;nbsp; gp.AddField_management(fc, fieldName, "LONG", 9, 3)&lt;/PRE&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Tue, 25 Jun 2013 22:10:02 GMT</pubDate>
      <guid>https://community.esri.com/t5/python-questions/copyfield-based-on-cxxxx/m-p/323380#M25178</guid>
      <dc:creator>ElaineKuo</dc:creator>
      <dc:date>2013-06-25T22:10:02Z</dc:date>
    </item>
    <item>
      <title>Re: copyfield based on Cxxxx</title>
      <link>https://community.esri.com/t5/python-questions/copyfield-based-on-cxxxx/m-p/323381#M25179</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;SPAN&gt;If the code in the shapefile name is the same as the code you want in your new field name, simply do this:&lt;/SPAN&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;PRE class="lia-code-sample line-numbers language-none"&gt;#Import standard library modules
import arcgisscripting, os


#Create the Geoprocessor object
gp = arcgisscripting.create(9.3)


#Set the input workspace
gp.Workspace= &lt;SPAN style="color: #333333; font-family: Courier New;"&gt;"H:/temp_D/test"&lt;/SPAN&gt;


#Get a list of the featureclasses in the input folder
fcs = gp.ListFeatureClasses()


#Loop through the fc's
for fc in fcs:


&amp;nbsp;&amp;nbsp;&amp;nbsp; # Get the numeric code from the shapefile name
&amp;nbsp;&amp;nbsp;&amp;nbsp; numCode = fc[4:8]


&amp;nbsp;&amp;nbsp;&amp;nbsp; # Build the field name
&amp;nbsp;&amp;nbsp;&amp;nbsp; fieldName = "C"+numCode+"D"&amp;nbsp;&amp;nbsp;&amp;nbsp; 


&amp;nbsp;&amp;nbsp;&amp;nbsp; #Add field to each SHP
&amp;nbsp;&amp;nbsp;&amp;nbsp; print "Updating file "+fc+" with fieldname "+fieldName+"..."
&amp;nbsp;&amp;nbsp;&amp;nbsp; gp.AddField_management(fc, fieldName, "LONG", 9, 3)&lt;/PRE&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Sat, 11 Dec 2021 15:21:53 GMT</pubDate>
      <guid>https://community.esri.com/t5/python-questions/copyfield-based-on-cxxxx/m-p/323381#M25179</guid>
      <dc:creator>RDHarles</dc:creator>
      <dc:date>2021-12-11T15:21:53Z</dc:date>
    </item>
    <item>
      <title>Re: copyfield based on Cxxxx</title>
      <link>https://community.esri.com/t5/python-questions/copyfield-based-on-cxxxx/m-p/323382#M25180</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;SPAN&gt;Thank you.&lt;/SPAN&gt;&lt;BR /&gt;&lt;SPAN&gt;The code worked wonderfully.&lt;/SPAN&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;SPAN&gt;The complete code (create a field (CXXXX) and copy a number to it) &lt;/SPAN&gt;&lt;BR /&gt;&lt;SPAN&gt;is&lt;/SPAN&gt;&lt;BR /&gt;&lt;PRE class="lia-code-sample line-numbers language-none"&gt;
##Script Name: Copy field
##Description: Copy field using CXXXX
##Created By: Elaine Kuo
##Date: 06/25/2013


#Import standard library modules
import arcgisscripting
import os

#Create the Geoprocessor object
gp = arcgisscripting.create(9.3)

#Set the input workspace
#GP.workspace = sys.argv[1]
#Set the workspace.
gp.Workspace= "H:/temp_D/test"

#Set the output workspace
#outWorkspace = sys.argv[2]
#Set the workspace. List all of the feature classes in the dataset
outWorkspace= "H:/temp_D"

#Get a list of the featureclasses in the input folder
fcs = gp.ListFeatureClasses()

# Loop through every item in the list that was just generated
for fc in fcs:

&amp;nbsp;&amp;nbsp;&amp;nbsp; # Break out the name, no path or extension, using the describe object.
&amp;nbsp;&amp;nbsp;&amp;nbsp; desc = gp.describe(fc)
&amp;nbsp;&amp;nbsp;&amp;nbsp; featureName = desc.name

&amp;nbsp;&amp;nbsp;&amp;nbsp; #Validate the new feature class name for the output workspace.
&amp;nbsp;&amp;nbsp;&amp;nbsp; OutFeatureClass = outWorkspace + os.sep + gp.ValidateTableName(fc,outWorkspace)

&amp;nbsp;&amp;nbsp;&amp;nbsp; #get file name
&amp;nbsp;&amp;nbsp;&amp;nbsp; fcName, fcExt = os.path.splitext(fc) 

&amp;nbsp; 
&amp;nbsp;&amp;nbsp;&amp;nbsp; #&amp;nbsp;&amp;nbsp; Get a list of the fields in the featureclass
&amp;nbsp;&amp;nbsp;&amp;nbsp; fields = gp.listFields(fc, "C*", "String")

&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; # Get the numeric code from the shapefile name
&amp;nbsp;&amp;nbsp;&amp;nbsp; numCode = fc[4:8]


&amp;nbsp;&amp;nbsp;&amp;nbsp; # Build the field name
&amp;nbsp;&amp;nbsp;&amp;nbsp; fieldName = "C"+numCode+"D"&amp;nbsp;&amp;nbsp;&amp;nbsp; 


&amp;nbsp;&amp;nbsp;&amp;nbsp; #Add field to each SHP
&amp;nbsp;&amp;nbsp;&amp;nbsp; print "Updating file "+fc+" with fieldname "+fieldName+"..."
&amp;nbsp;&amp;nbsp;&amp;nbsp; gp.AddField_management(fc, fieldName, "LONG", 9)


&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; # Make temporary featureclasses
&amp;nbsp;&amp;nbsp;&amp;nbsp; gp.MakeFeatureLayer(fc,"lyr")
&amp;nbsp;&amp;nbsp;&amp;nbsp; 
&amp;nbsp;&amp;nbsp;&amp;nbsp; #&amp;nbsp;&amp;nbsp; Get a list of the fields in the featureclass
&amp;nbsp;&amp;nbsp;&amp;nbsp; fields = gp.ListFields("lyr", "C*", "String")
&amp;nbsp;&amp;nbsp;&amp;nbsp; 
&amp;nbsp;&amp;nbsp;&amp;nbsp; # Loop through every item in the list that was just generated 
&amp;nbsp;&amp;nbsp;&amp;nbsp; for field in fields:

&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; gp.toolbox = "Data Management"

&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; # Select records to be copied (C*, i.e. C7658)
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; query = "\"%s\" = 'R'" % field.Name
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; gp.SelectLayerByAttribute("lyr", "ADD_TO_SELECTION", query)

&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; 
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; # copy values in existing fields to the new field 
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; gp.CalculateField("lyr", fieldName, "1", "PYTHON_9.3")



gp.AddMessage(gp.GetMessages())
print gp.GetMessages()
&amp;nbsp;&amp;nbsp; 
&lt;/PRE&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Sat, 11 Dec 2021 15:21:56 GMT</pubDate>
      <guid>https://community.esri.com/t5/python-questions/copyfield-based-on-cxxxx/m-p/323382#M25180</guid>
      <dc:creator>ElaineKuo</dc:creator>
      <dc:date>2021-12-11T15:21:56Z</dc:date>
    </item>
    <item>
      <title>Re: copyfield based on Cxxxx</title>
      <link>https://community.esri.com/t5/python-questions/copyfield-based-on-cxxxx/m-p/323383#M25181</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;SPAN&gt;Glad I could help.&lt;/SPAN&gt;&lt;BR /&gt;&lt;SPAN&gt;R.D.&lt;/SPAN&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Thu, 27 Jun 2013 12:48:09 GMT</pubDate>
      <guid>https://community.esri.com/t5/python-questions/copyfield-based-on-cxxxx/m-p/323383#M25181</guid>
      <dc:creator>RDHarles</dc:creator>
      <dc:date>2013-06-27T12:48:09Z</dc:date>
    </item>
    <item>
      <title>Re: copyfield based on Cxxxx</title>
      <link>https://community.esri.com/t5/python-questions/copyfield-based-on-cxxxx/m-p/323384#M25182</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;SPAN&gt;I see this snippet in the code, but don't know what it is used for as it looks like you get the name from the os.path.split section:&lt;/SPAN&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;PRE class="lia-code-sample line-numbers language-none"&gt;
&amp;nbsp;&amp;nbsp;&amp;nbsp; # Break out the name, no path or extension, using the describe object.
&amp;nbsp;&amp;nbsp;&amp;nbsp; desc = gp.describe(fc)
&amp;nbsp;&amp;nbsp;&amp;nbsp; featureName = desc.name

&lt;/PRE&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;SPAN&gt;I don't see anywhere else that you are using the desc or featureName variables.&amp;nbsp; If so, the describe is fairly heavy operation, especially within a for loop.&lt;/SPAN&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;SPAN&gt;If it really isn't needed, would probably decrease your run time substatially if removed.&lt;/SPAN&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;SPAN&gt;R_&lt;/SPAN&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Sat, 11 Dec 2021 15:21:58 GMT</pubDate>
      <guid>https://community.esri.com/t5/python-questions/copyfield-based-on-cxxxx/m-p/323384#M25182</guid>
      <dc:creator>RhettZufelt</dc:creator>
      <dc:date>2021-12-11T15:21:58Z</dc:date>
    </item>
    <item>
      <title>Re: copyfield based on Cxxxx</title>
      <link>https://community.esri.com/t5/python-questions/copyfield-based-on-cxxxx/m-p/323385#M25183</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;BLOCKQUOTE class="jive-quote"&gt;I see this snippet in the code, but don't know what it is used for as it looks like you get the name from the os.path.split section:&lt;BR /&gt;&lt;BR /&gt;&lt;PRE class="plain" name="code"&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; # Break out the name, no path or extension, using the describe object. &amp;nbsp;&amp;nbsp;&amp;nbsp; desc = gp.describe(fc) &amp;nbsp;&amp;nbsp;&amp;nbsp; featureName = desc.name &lt;/PRE&gt;&lt;DIV style="display:none;"&gt; &lt;/DIV&gt;&lt;BR /&gt;&lt;BR /&gt;I don't see anywhere else that you are using the desc or featureName variables.&amp;nbsp; If so, the describe is fairly heavy operation, especially within a for loop.&lt;BR /&gt;&lt;BR /&gt;If it really isn't needed, would probably decrease your run time substatially if removed.&lt;BR /&gt;&lt;BR /&gt;R_&lt;/BLOCKQUOTE&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;SPAN&gt;Nor do these lines look necessary:&lt;/SPAN&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;PRE class="plain" name="code"&gt;#Validate the new feature class name for the output workspace. &amp;nbsp;&amp;nbsp;&amp;nbsp; OutFeatureClass = outWorkspace + os.sep + gp.ValidateTableName(fc,outWorkspace) &amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; #get file name &amp;nbsp;&amp;nbsp;&amp;nbsp; fcName, fcExt = os.path.splitext(fc) &amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; #Get a list of the fields in the featureclass &amp;nbsp;&amp;nbsp;&amp;nbsp; fields = gp.listFields(fc, "C*", "String")&lt;/PRE&gt;&lt;DIV style="display:none;"&gt; &lt;/DIV&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Thu, 27 Jun 2013 17:47:05 GMT</pubDate>
      <guid>https://community.esri.com/t5/python-questions/copyfield-based-on-cxxxx/m-p/323385#M25183</guid>
      <dc:creator>RDHarles</dc:creator>
      <dc:date>2013-06-27T17:47:05Z</dc:date>
    </item>
    <item>
      <title>Re: copyfield based on Cxxxx</title>
      <link>https://community.esri.com/t5/python-questions/copyfield-based-on-cxxxx/m-p/323386#M25184</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;SPAN&gt;Didn't even recognize that.&amp;nbsp; Guess I really wasn't trying to pick apart the code, just that I have been "bitten" by describe statements within a loop before, so that really stood out to me.&lt;/SPAN&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;SPAN&gt;R_&lt;/SPAN&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Thu, 27 Jun 2013 18:15:57 GMT</pubDate>
      <guid>https://community.esri.com/t5/python-questions/copyfield-based-on-cxxxx/m-p/323386#M25184</guid>
      <dc:creator>RhettZufelt</dc:creator>
      <dc:date>2013-06-27T18:15:57Z</dc:date>
    </item>
    <item>
      <title>Re: copyfield based on Cxxxx</title>
      <link>https://community.esri.com/t5/python-questions/copyfield-based-on-cxxxx/m-p/323387#M25185</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;BLOCKQUOTE class="jive-quote"&gt;Didn't even recognize that.&amp;nbsp; Guess I really wasn't trying to pick apart the code, just that I have been "bitten" by describe statements within a loop before, so that really stood out to me.&lt;BR /&gt;&lt;BR /&gt;R_&lt;/BLOCKQUOTE&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;SPAN&gt;Good to know about the Describe, didn't know it was so "computer intensive".&lt;/SPAN&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Thu, 27 Jun 2013 18:18:59 GMT</pubDate>
      <guid>https://community.esri.com/t5/python-questions/copyfield-based-on-cxxxx/m-p/323387#M25185</guid>
      <dc:creator>RDHarles</dc:creator>
      <dc:date>2013-06-27T18:18:59Z</dc:date>
    </item>
  </channel>
</rss>

