I can't get this script to work. I am trying to create create a script that takes a point file with a single point representing a location and a field in its table "UNIT_NUMBE" and create duplicate points for that single point based on the value in this "UNIT_NUMBE" field.
Attached is the script that I have so far:
It bails out at line28 or the line that reads CountRange = range(InRow.count)
I get a runtime error: Row: Field count does not exist
Anyone help me with this. Thanks in Advanced.
Solved! Go to Solution.
Code in question (I believe you do need a field called 'count', although I'm not familiar with the old cursors, anymore):
import sys, arcpy
#InFeatClass = sys.argv[1]
#OutFeatClass = sys.argv[2]
InFeatClass = "S:/GIS_Public/GIS_Data/DefaultGDB/Default.gdb/tempUnitsperParcel"
OutFeatClass = "S:/GIS_Public/GIS_Data/DefaultGDB/Default.gdb/tempUnitsperParcel4"
# overwriting output is ok.
arcpy.env.overwriteOutput = True
# copy the count = 1 features to create a new feature class, saves having to do
# new feature class, copy spatial reference and fields..
arcpy.Select_analysis(InFeatClass,OutFeatClass,"UNIT_NUMBE = 1")
# setup cursor objects - search the source, isert the destination
InsCur = arcpy.InsertCursor(OutFeatClass)
SrchCur = arcpy.SearchCursor(InFeatClass,"UNIT_NUMBE > 1")
# get the list of fields to copy
FieldList = arcpy.ListFields(InFeatClass,"*")
NoCalcFields = ["FID","OBJECTID","SHAPE"]
for InRow in SrchCur:
# create a range and then iterate over it
# inserting a new row for each count
CountRange = range(InRow.count)
for indx in CountRange:
newRow = InsCur.newRow() # create a new (empty) feature
# copy values from the source to the destination
for ThisField in FieldList:
if ThisField.name.upper() not in NoCalcFields:
newRow.setValue(ThisField.name,InRow.getValue(ThisField.name))
# copy the shape
newRow.setValue("SHAPE",InRow.getValue("SHAPE"))
# Store it
InsCur.insertRow(newRow)
to save a download and unzip, can you check the code to see if it is hardcoded to a field named 'count' or post a url to the original
Code in question (I believe you do need a field called 'count', although I'm not familiar with the old cursors, anymore):
import sys, arcpy
#InFeatClass = sys.argv[1]
#OutFeatClass = sys.argv[2]
InFeatClass = "S:/GIS_Public/GIS_Data/DefaultGDB/Default.gdb/tempUnitsperParcel"
OutFeatClass = "S:/GIS_Public/GIS_Data/DefaultGDB/Default.gdb/tempUnitsperParcel4"
# overwriting output is ok.
arcpy.env.overwriteOutput = True
# copy the count = 1 features to create a new feature class, saves having to do
# new feature class, copy spatial reference and fields..
arcpy.Select_analysis(InFeatClass,OutFeatClass,"UNIT_NUMBE = 1")
# setup cursor objects - search the source, isert the destination
InsCur = arcpy.InsertCursor(OutFeatClass)
SrchCur = arcpy.SearchCursor(InFeatClass,"UNIT_NUMBE > 1")
# get the list of fields to copy
FieldList = arcpy.ListFields(InFeatClass,"*")
NoCalcFields = ["FID","OBJECTID","SHAPE"]
for InRow in SrchCur:
# create a range and then iterate over it
# inserting a new row for each count
CountRange = range(InRow.count)
for indx in CountRange:
newRow = InsCur.newRow() # create a new (empty) feature
# copy values from the source to the destination
for ThisField in FieldList:
if ThisField.name.upper() not in NoCalcFields:
newRow.setValue(ThisField.name,InRow.getValue(ThisField.name))
# copy the shape
newRow.setValue("SHAPE",InRow.getValue("SHAPE"))
# Store it
InsCur.insertRow(newRow)
Neil and Darren hit the nail on the head. I changed the "NUMBE" field to "Count" and the code ran perfectly.
Thanks!