I do it directly in ArcGIS, and have the toolbox visible in the catalog window. If you don't see your tool, that means there's something wrong with the syntax. you can right click on the toolbox and select Check Syntax, and get some clues that way, and the error descriptions are pretty good, with line number of the offending piece of code. For this, I paste my code in a session of Notepad++ since I don't think IDLE has that, or I haven't figured out. Another thing I've notice about IDLE is that if you customize your colors for keywords, stings, comments, etc. it works great on .py files, but it doesn't in .pyt.You have to keep executing your code for debugging, and make corrections based on the error messages. Also, every time you make changes to the code, you must right click on the tool and click on Refresh. I found that deselecting after reading is better than trying to filter your selections. Following is my finished working code, where you will see where the deselection lines go.OK, is 7 minutes after 5, and I'm so out of here it's not even funny--YABADABADOO!!!import arcpy, sys, os
class Toolbox(object):
def __init__(self):
"""Define the toolbox (the name of the toolbox is the name of the
.pyt file)."""
self.label = "Location Map Toolbox"
self.alias = "Location Map"
# List of tool classes associated with this toolbox
self.tools = [FillTitleBlock]
class FillTitleBlock(object):
def __init__(self):
"""Define the tool (tool name is the name of the class)."""
self.label = "Fill Title Block"
self.description = "Fill Title Block"
self.canRunInBackground = False
# user project data input
def getParameterInfo(self):
"""Define parameter definitions"""
#params = None
#return params
ProjectNumber= arcpy.Parameter(
displayName= "Project Number",
name= "ProjectNumber",
datatype= "GPString",
parameterType= "Required",
direction= "Input")
ProjectTitle= arcpy.Parameter(
displayName= "Project Title",
name= "ProjectTitle",
datatype= "GPString",
parameterType= "Required",
direction= "Input")
ParcelID= arcpy.Parameter(
displayName= "Parcel ID",
name= "ParcelID",
datatype= "GPString",
parameterType= "Required",
direction= "Input")
parameters= [ProjectNumber, ProjectTitle, ParcelID]
return parameters
def isLicensed(self):
"""Set whether tool is licensed to execute."""
return True
def updateParameters(self, parameters):
"""Modify the values and properties of parameters before internal
validation is performed. This method is called whenever a parameter
has been changed."""
return
def updateMessages(self, parameters):
"""Modify the messages created by internal validation for each tool
parameter. This method is called after internal validation."""
return
def execute(self, parameters, messages):
"""The source code of the tool."""
#Layout and Table of Contents variables
mxd= arcpy.mapping.MapDocument("CURRENT")
df = arcpy.mapping.ListDataFrames(mxd, "Base Map")[0]
lyr= "GIS.GISADMIN.parcels"
ZIP= "GIS.GISADMIN.Zipcodes"
TAZ= "GIS.GISADMIN.TAZ_LRTP2009_2035_371"
DIS= "CommissionDistrict"
#Parameters
ProjNum= parameters[0].valueAsText
ProjTit= parameters[1].valueAsText
ParcelID= parameters[2].valueAsText
#Input title block data
for txtelem in arcpy.mapping.ListLayoutElements(mxd, "TEXT_ELEMENT"):
if txtelem.name == "PRJ_NUM":
txtelem.text = ProjNum
elif txtelem.name == "PRJ_TIT":
txtelem.text = ProjTit
elif txtelem.name == "PID":
txtelem.text = ParcelID
#Select parcel and zoom to it
selPID= "\"VPARCEL\" = '" + ParcelID + "'"
arcpy.SelectLayerByAttribute_management(lyr, "NEW_SELECTION", selPID)
df.zoomToSelectedFeatures() #option 1
# Without lyr, it zooms to all selected layers (below). With this argument, I get TypeError: zoomToSelectedFeatures() takes exactly 1 argument (2 given)
#df.panToExtent(lyr.getSelectedExtent()) #option 2
# I get AttributeError: 'str' object has no attribute 'getSelectedExtent'
df.scale = df.scale * 1.25
#arcpy.RefreshActiveView() #This used to be at the end of the script, but I moved it here hoping the layer selections below would not get zoomed too: FAIL
#Input address, TAZ, and commission district
arcpy.MakeFeatureLayer_management(lyr, "ParSel", selPID)
parLyr= arcpy.SelectLayerByLocation_management(lyr,"ARE_IDENTICAL_TO","ParSel")
rows= arcpy.SearchCursor(parLyr)
row= rows.next()
lblAddress= arcpy.mapping.ListLayoutElements(mxd, "TEXT_ELEMENT", "PRJ_ADD")[0]
if row.isNull("PHYSADDR") == True:
lblAddress.text= "None found."
else:
lblAddress.text= row.getValue("PHYSADDR")
#Add zip code and city--this does not work well with some properties if adjacent or accross zip bounds
## CITLyr= arcpy.SelectLayerByLocation_management(ZIP,"INTERSECT","ParSel")
## rows= arcpy.SearchCursor(CITLyr)
## row= rows.next()
## lblCIT= arcpy.mapping.ListLayoutElements(mxd, "TEXT_ELEMENT", "PRJ_CIT")[0]
## lblCIT.text= row.getValue("CITY")
## arcpy.SelectLayerByAttribute_management(CITLyr, "REMOVE_FROM_SELECTION", "")
##
## ZIPLyr= arcpy.SelectLayerByLocation_management(ZIP,"INTERSECT","ParSel")
## rows= arcpy.SearchCursor(ZIPLyr)
## row= rows.next()
## lblZIP= arcpy.mapping.ListLayoutElements(mxd, "TEXT_ELEMENT", "PRJ_ZIP")[0]
## lblZIP.text= row.getValue("ZIPCODE")
## arcpy.SelectLayerByAttribute_management(ZIPLyr, "REMOVE_FROM_SELECTION", "")
TAZLyr= arcpy.SelectLayerByLocation_management(TAZ,"INTERSECT","ParSel")
list= []
lblTAZ= arcpy.mapping.ListLayoutElements(mxd, "TEXT_ELEMENT", "TAZ")[0]
rows= arcpy.SearchCursor(TAZLyr)
row= rows.next()
while row:
ParTAZ= row.getValue("ctyTAZ")
list.append(ParTAZ)
row= rows.next()
lblTAZ.text= str(list).translate(None, '[]')
arcpy.SelectLayerByAttribute_management(TAZLyr, "REMOVE_FROM_SELECTION", "")
DISLyr= arcpy.SelectLayerByLocation_management(DIS,"INTERSECT","ParSel")
rows= arcpy.SearchCursor(DISLyr)
row= rows.next()
lblDIS= arcpy.mapping.ListLayoutElements(mxd, "TEXT_ELEMENT", "COM")[0]
lblDIS.text= row.getValue("DISTRICT")
arcpy.SelectLayerByAttribute_management(DISLyr, "REMOVE_FROM_SELECTION", "")
arcpy.RefreshActiveView()
mxd.saveACopy(r"G:\PCM_Jorge\LOCATION_MAPS\0-MAPS\\" + ProjNum + ".mxd") #directory must exist
arcpy.mapping.ExportToPDF(mxd, r"G:\PCM_Jorge\LOCATION_MAPS\0-MAPS\PDF\\" + ProjNum + ".pdf")
## mxd.save() ##this will overwrite the template
del mxd, row, rows, lblAddress, lblTAZ, lblDIS,
return