rcmiedema

InsertCursor: Using default value for field

Discussion created by rcmiedema on Jun 29, 2011
Latest reply on Jun 29, 2011 by csny490
I have a python script that inserts new line objects in an existing feature class. This feature class has some fields with default values. How do I generate the default values in the new rows as in an edit session within ArcMap?

# Import system modules
import sys, string, os, arcgisscripting

# Create the Geoprocessor object
gp = arcgisscripting.create()

# Load required toolboxes...
gp.AddToolbox("c:/Archivos de programa/ArcGIS/ArcToolbox/Toolboxes/Data Management Tools.tbx")

# Script arguments...
acoLines = gp.GetParameterAsText(0)

readTable = gp.GetParameterAsText(1)

rows = gp.searchcursor(readTable)
insertCur = gp.InsertCursor(acoLines)

# Get the first feature in the searchcursor
lineArray = gp.CreateObject("Array")
pnt0 = gp.CreateObject("Point")
pnt1 = gp.CreateObject("Point")

row = rows.next()
while row:
try:
coordX0 = row.NEAR_X
coordY0 = row.NEAR_Y
coordX1 = row.POINT_X
coordY1 = row.POINT_Y
gp.AddMessage(row.OBJECTID)
pnt0.id = 0
pnt0.x = coordX0
pnt0.y = coordY0
lineArray.add(pnt0)
pnt1.id = 1
pnt1.x = coordX1
pnt1.y = coordY1
lineArray.add(pnt1)
feat = insertCur.NewRow()
feat.shape = lineArray
insertCur.InsertRow(feat)
lineArray.RemoveAll()
row = rows.next()
except:
gp.AddMessage('error')

#gp.SetParameterAsText(2,acoLines)

Outcomes