classToolbox(object): def__init__(self): """Define the toolbox (the name of the toolbox is the name of the .pyt file).""" self.label = "Toolbox" self.alias = ""
# List of tool classes associated with this toolbox self.tools = [Tool]
classTool(object): def__init__(self): """Define the tool (tool name is the name of the class).""" self.label = "Tool" self.description = "" self.canRunInBackground = False
defisLicensed(self): """Set whether tool is licensed to execute.""" returnTrue
defupdateParameters(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
defupdateMessages(self, parameters): """Modify the messages created by internal validation for each tool parameter. This method is called after internal validation.""" return
defexecute(self, parameters, messages): """The source code of the tool.""" return
# Get tool parameters inWorkspace = parameters[0].valueAsText arcpy.AddMessage("###Input Workspace is {0}".format(inWorkspace))
ClipArea = parameters[1].valueAsText arcpy.AddMessage("###Clip Area is {0}".format(ClipArea))
outWorkspace = parameters[2].valueAsText arcpy.AddMessage("###Out Workspace is {0}".format(outWorkspace))
# Clip Feature by Batch arcpy.env.workspace = inWorkspace
# Clip Vector FeatureClasses = arcpy.ListFeatureClasses() arcpy.AddMessage("Input Workspace contains {0}".format(FeatureClasses)) for fc in FeatureClasses: arcpy.AddMessage(">> Clipping {0}".format(fc)) arcpy.Clip_analysis(fc,ClipArea, os.path.join(outWorkspace,fc)) arcpy.AddMessage("{0} has been clipped.".format(os.path.join(outWorkspace,fc)))