I Cannot find what this error means or what could be causing it? Script worked until I added the lines under "Set map label to containing quad name". My environment is ArcGIS 10.1 SP1, Windows 7. Here is my code:
import arcpy
#Define I/O and workspaces
arcpy.env.workspace = "FolderPath"
arcpy.env.overwriteOutput = True
mxd = arcpy.mapping.MapDocument("MXDPath.mxd")
df = arcpy.mapping.ListDataFrames(mxd)[0]
outpath = arcpy.GetParameterAsText(2)
def getAuthCode(lon):
if lon >= -126.0 and lon < -120.0:
authCode = 26910 #UTM Zone 10N
elif lon >= -120.0 and lon < -114.0:
authCode = 26911 #UTM Zone 11N
elif lon >= -114.0 and lon < -108.0:
authCode = 26912 #UTM Zone 12N
elif lon >= -108.0 and lon < -102.0:
authCode = 26913 #UTM Zone 13N
elif lon >= -102.0 and lon < -96.0:
authCode = 26914 #UTM Zone 14N
elif lon >= -96.0 and lon < -90.0:
authCode = 26915 #UTM Zone 15N
elif lon >= -90.0 and lon < -84.0:
authCode = 26916 #UTM Zone 16N
elif lon >= -84.0 and lon < -78.0:
authCode = 26917 #UTM Zone 17N
elif lon >= -78.0 and lon < -72.0:
authCode = 26918 #UTM Zone 18N
elif lon >= -72.0 and lon < -66.0:
authCode = 26919 #UTM Zone 19N
else:
authCode = 4326 # WGS84
return authCode
#Create extent/spatial referenece objects
lat = arcpy.GetParameterAsText(0)
lon = arcpy.GetParameterAsText(1)
WGS84 = arcpy.SpatialReference(4326) #Creates spatial reference variable to switch back to later
UTM = arcpy.SpatialReference(getAuthCode(lon))
df.spatialReference = WGS84 #Set spatial reference to WGS84
resetPT = arcpy.Extent(-97.747957, 30.280553, -97.747957, 30.280553)
#Set map label to containing quad name
point = arcpy.Point(lon, lat)
ptGeo = arcpy.PointGeometry(point, WGS84)
quadPath = "LayerPath.lyr"
quadLyr = arcpy.mapping.Layer(quadPath) #arcpy.mapping.ListLayers(mxd)[0]
selectedLyr = arcpy.SelectLayerByLocation_management(quadLyr, "INTERSECT", ptGeo)
cursor = arcpy.da.SearchCursor(selectedLyr, "QUAD_NAME")
quadName = ""
for row in cursor:
quadName = str(row)
label = arcpy.mapping.ListLayoutElements(mxd, "TEXT_ELEMENT", "Label")[0]
label.text = "NWI Map" + "\n" + "Quad: " + quadName[3:-3] + ", TX"
label.elementPositionX = 0.3
label.elementPositionY = 0.3
#Pans to centerpoint and sets scale to 1:12000
extent = arcpy.Extent(lon, lat, lon, lat)
df.panToExtent(extent)
df.spatialReference = UTM #Temporarily set spatial reference to correct UTM zone
df.scale = 12000
arcpy.RefreshActiveView()
#Export map to ES# folder
arcpy.mapping.ExportToPDF(mxd, outpath, resolution=300) #exportToPDF
#Reset extent/spatial reference
df.spatialReference = WGS84
df.panToExtent(resetPT)
arcpy.RefreshActiveView()
mxd.save()