Monday 21 August 2017

arcpy - Using InsertCursor in ModelBuilder?


I've created a function in my model to insert row in a table I've created. The problem is if it runs the InsertCursor function before the end of my program. My model executes incorrectly. I believe it's because the InsertCursor doesn't actually output anything. I get this message: "The process did not execute because the precondition is false." if I manually try to step through it. The message I get initially upon running model is: "All the inputs are not current." If I remove the precondition, it executes properly except it wants to run the function last, after it's already created the excel document that I'm trying to add the appended table to. I've already attempted this fix.


Here's the function:


import arcpy, inspect, os


fc = os.path.dirname(os.path.abspath(inspect.getfile(inspect.currentframe()))) + "\ProposedDesignDB.mdb\AnodeEquipment"
fields = ['MATERIALNUMBER','MATERIALNUMBERTEXT']

def AnodeUpdate(y):
cursor = arcpy.da.InsertCursor(fc, fields)
for x in xrange (0, y):
newRow = ["100212","ANODE 1 LB 3 FT LEAD 12 WHITE COPPER"]
cursor.insertRow(newRow)
del newRow

del cursor

Has anyone else ever had this issue? enter image description here



Answer



The solution was to create a separate model that just processed my line features. That way it ran the InsertCursor last, and then tied it back into my current model and ran normally.


No comments:

Post a Comment

arcpy - Changing output name when exporting data driven pages to JPG?

Is there a way to save the output JPG, changing the output file name to the page name, instead of page number? I mean changing the script fo...