InsertCursor: Using default value for field

546
1
06-29-2011 07:31 AM
RichardMiedema
New Contributor
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)
Tags (2)
0 Kudos
1 Reply
ChrisSnyder
Regular Contributor III
Not too suprised this isn't working in Python. Try using the gp.AssignDefaultToField_management() tool again directly in the script, otherwise, maybe just hardcode the default values in the insert cursor?
0 Kudos