Original User: SVisovskyI'm having a heck of a problem getting a script tool to work in model builder. The script works just fine on its own when run from IDLE, but it invariably throws the same error when it runs as part of my model. I'm using the pyodbc module to talk to an SQL database and run a pair of stored procedures there as part of my model. The stored procedures populate the FACILITYID field in two layers; the rest of the model puts the FACILITIYID from PlantingSpace into the FACILITYID_PS field in TreePoint based on spatial intersection. I took out the assorted connection details, but I double checked to make sure they all work before making the changes here. The most annoying thing is that it does work sometimes. I'm not certain, but I think that's the case the first time it runs after opening ArcCatalog/ArcMap. That said, the error I'm getting is:AttributeError: 'module' object has no attribute 'lowercase'I suspect either that I set up the script tool incorrectly, Model Builder doesn't like python in general or pyodbc in particular, or that Model Builder doesn't like using scripts as preconditions. I've also read something about importing multiple python modules causing problems, but I'm new enough to scripting that I have no idea what any of that discussion means. I'm running ArcGIS 10.0, SP2 on Win7 64bit. The server is running MS SQL Server 2005. Any advice would be helpful. Here's the model:[ATTACH=CONFIG]25611[/ATTACH]and the way I set up the script tool:[ATTACH=CONFIG]25612[/ATTACH][ATTACH=CONFIG]25612[/ATTACH]and here's my code:
import arcpy
import pyodbc
#variables yay
Tcount = 0;
Pcount = 0;
Prow = 0;
Trow = 0;
OutputSuccess = 'false';
arcpy.SetParameterAsText(0, 'false')
#Establish DB connection
cnxn = pyodbc.connect('DRIVER={SQL Server};SERVER=REDACTED;DATABASE=REDACTED;UID=REDACTED;PWD=REDACTED;autocommit=True')
#Create cursors for Trees (Tcursor, Trows)(Pcursor, Prows)
#then selects null values and blank strings in FACILITYID
Tcursor = cnxn.cursor()
Tcursor.execute("SELECT (OBJECTID) FROM *TREEPOINT* WHERE FACILITYID IS NULL OR FACILITYID = ''")
Trows = Tcursor.fetchall()
#Loop one executes stored procedure (takes OBJECTID) for every row with a null FACILITYID in TreePoint
#Prints the total number of records or says there are no null IDs
if len(Trows) > 0:
for Trow in Trows:
ExecuteString = "exec *STORED PROCEDURE* %i" %int(Trow.OBJECTID)
Tcursor.execute(ExecuteString)
Tcount+= 1
arcpy.AddMessage('Planting Space count: ' + str(Tcount))
else:
arcpy.AddMessage('No NULL FacilityIDs found in TreePoint')
Tcursor.close()
#Create cursors for PlantingSpace (Pcursor, Prows)
#then selects null values and blank strings in FACILITYID
Pcursor = cnxn.cursor()
Pcursor.execute("SELECT (OBJECTID) FROM *PLANTINGSPACE* WHERE FACILITYID IS NULL OR FACILITYID = ''")
Prows = Pcursor.fetchall()
#Loop two executes stored procedure (takes OBJECTID) for every row with a null FACILITYID in PlantingSpace
#Prints the total number of records or says there are no null IDs
if len(Prows) > 0:
for Prow in Prows:
ExecuteString = "exec *STOREDPROCEDURE* %i" %int(Prow.OBJECTID)
Pcursor.execute(ExecuteString)
Pcount+= 1
arcpy.AddMessage('Planting Space count: ' + str(Pcount))
else:
arcpy.AddMessage('No NULL FacilityIDs in Planting Spaces')
Pcursor.close()
#Create boolean output value for use in model
#Should be 1/true if script ran, 0/false if it didn't.
if (Tcount>0 or Pcount>0):
arcpy.SetParameterAsText(0, 'true')
else:
arcpy.SetParameterAsText(0, 'false')
#commit changes to DB and close connection
cnxn.commit()
cnxn.close()