You are the smartest man alive!!! Thank you soo much, worked like a charm!
Here is the code in case anyone is interested in doing something similar:
Code:
# This script allows a user to input a parcel ID number
# This will automatically save the map to PDF so it can be printed
# Written by Caleb Mackey 9/17/2012
# Print PDF section courtesy of Luke Pinner 9/18/2012
import arcpy, os, sys, traceback
import subprocess
arcpy.env.overwriteOutput = True
def userinput():
mxd = arcpy.mapping.MapDocument("G:\\Map_Documents\\Walkin_requests\\Customer_map.mxd")
df = arcpy.mapping.ListDataFrames(mxd, "Main")[0]
parcels = arcpy.mapping.ListLayers(mxd, "Parcels GIS Acres", df)[0]
pdfpath = 'C:\\Documents and Settings\\gis\\Desktop\\PRINT_MAPS\\'
txtfile = pdfpath + 'Parcelmap_ERROR.txt'
acroread = r'C:\Program Files\Adobe\Reader 10.0\Reader\AcroRd32.exe'
try:
print "Enter Parcel Number WITHOUT dashes and hit ENTER"
parcelid = raw_input()
parcel_num = str(parcelid)
print 'selecting parcel...'
query = "SOL_PID ='%s'" % parcel_num
arcpy.SelectLayerByAttribute_management(parcels, "NEW_SELECTION", query)
result = arcpy.GetCount_management(parcels)
if str(result) == '0':
print 'Invalid SQL statement, check parcel ID'
print 'Please verify the Parcel ID and try again'
return userinput();
elif str(result) > 0:
df.zoomToSelectedFeatures()
df.extent = parcels.getSelectedExtent(True)
df.scale *= 1.65
arcpy.RefreshActiveView()
print 'Exporting to pdf...'
pdf = pdfpath + str(parcel_num) + '.pdf'
pdfname = str(parcel_num) + '.pdf'
if arcpy.Exists(pdf):
arcpy.Delete_management(pdf)
arcpy.mapping.ExportToPDF(mxd,pdfpath + str(parcel_num) + '.pdf')
del mxd
print 'PDF Exported, to view open ' + str(pdfname) + ' in the "PRINT MAPS" folder.'
print 'Sending document to default printer'
#### Print PDF Code thanks to Luke Pinner #####
# '"%s"'is to wrap double quotes around paths
# as subprocess will use list2cmdline internally if we pass it a list
# which escapes double quotes and Adobe Reader doesn't like that
cmd='"%s" /N /T "%s"' %(acroread,pdf)
proc = subprocess.Popen(cmd,stdout=subprocess.PIPE,stderr=subprocess.PIPE)
stdout,stderr=proc.communicate()
exit_code=proc.wait()
print 'Successful'
except:
print arcpy.GetMessages(2)
try:
userinput()
except:
# Get the traceback object
tb = sys.exc_info()[2]
tbinfo = traceback.format_tb(tb)[0]
# Concatenate information together concerning the error into a message string
pymsg = "PYTHON ERRORS:\nTraceback info:\n" + tbinfo + "\nError Info:\n" + str(sys.exc_info()[1])
msgs = "ArcPy ERRORS:\n" + arcpy.GetMessages(2) + "\n"
# Return python error messages for use in script tool or Python Window
arcpy.AddError(pymsg)
arcpy.AddError(msgs)
# Print Python error messages for use in Python / Python Window
print pymsg + "\n"
print msgs
# Print Log file
txtFile = open(txtfile, "w")
txtFile.write(pymsg)
txtFile.write(msgs)
txtFile.write(query)
txtFile.close()
Bookmarks