-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathhelloWorldToolbox.pyt
More file actions
282 lines (250 loc) · 12.6 KB
/
helloWorldToolbox.pyt
File metadata and controls
282 lines (250 loc) · 12.6 KB
1
# -*- coding: utf-8 -*-import arcpy##--------------------------------------------------------##if __name__ == "__main__": # call to generate metadata from toolbox from pyt_meta import create_tb_meta tb_meta = create_tb_meta(__file__, True)##--------------------------------------------------------## class Toolbox(object): def __init__(self): """Define the toolbox (the name of the toolbox is the name of the .pyt file).""" """Define the toolbox (the name of the toolbox is the name of the .pyt file).""" self.label = "Hello World Toolbox" self.alias = "helloworldtoolbox" # required to call custom tools via python scripts controls name and alias properties self.description = '''Some description of the toolbox that is a multiline string''' # List of tool classes associated with this toolbox self.tools = [helloTool, byeTool]## Example of available metadata tags and values for toolbox level## metadata within the standard ESRI "Item Description metadata style"## *Tags can be added or removed to sync with additional metadata styles*## *Metadata declared at the tool level will override toolbox level metadata*## ____________________________________________________________## self.CreaDate = '20210720'## self.CreaTime = '17120606'## self.ArcGISFormat = '1.0'## self.SyncOnce = 'TRUE'## self.ModDate = '20210621'## self.ModTime = '13165353'## self.minScale = '150000000'## self.maxScale = '5000'## self.ArcGISProfile = 'ItemDescription'## self.arcToolboxHelpPath = 'D:\Help\gp'## self.resTitle = 'helloWorldToolbox'## self.idPurp = '''Some description of the toolbox## that is a multiline string'''## self.searchKeys = ['hello', 'world', 'toolbox']## self.idAbs = '''Some abstract of the toolbox## that is a multiline string'''## self.idCredit = '''Point of Contact (POC): Jane Doe## Organization: Hoolie INC.## Email: Jane.Doe@hoolie.co'''## self.useLimit = '''Copyright Notice: Hoolie explicitly owns## all rights to this toolbox.'''## self.formatName = 'ArcToolbox Toolbox'## self.mdDateSt = '20210701'## ____________________________________________________________ class helloTool(object): def __init__(self): """Define the tool (tool name is the name of the class).""" self.label = "Hello Tool" self.category = 'Tool examples' self.description = '''This tool prints a simple hello statement in ArcGIS Pro''' self.canRunInBackground = False## Example of available metadata tags and values for tool level## metadata within the standard ESRI "Item Description metadata style"## *Tags can be added or removed to sync with additional metadata styles*## *Metadata declared at the tool level will override toolbox level metadata*## ____________________________________________________________## self.CreaDate = '20210720'## self.CreaTime = '17120606'## self.ArcGISFormat = '1.0'## self.SyncOnce = 'TRUE'## self.ModDate = '20210701'## self.ModTime = '16591414'## self.minScale = '150000000'## self.maxScale = '5000'## self.arcToolboxHelpPath = 'D:\Help\gp'## self.summary = '''This tool prints a simple## hello statement in ArcGIS Pro'''## self.usage = '''This tool is useful in printing a simple## hello statement in ArcGIS Pro'''#### self.scriptExamples = {'Code Sample 1 ': {## 'desc' : 'Sample 1 of the Hello World tool code in python:',## 'code' : ['def hello_world_func():',## ' print("Hello World!")']## },## 'Code Sample 2 ': {## 'desc' : 'Sample 2 of the Hello World tool code in python:',## 'code' : ['def hello_world_func():',## ' print("Hello World * 2!")']## } ## }## ## self.resTitle = 'helloworldtoolbox.(Uncategorized)'## self.idCredit = '''Point of Contact (POC): Jill Doe## Organization: Hoolie INC.## Email: Jill.Doe@hoolie.co'''## self.useLimit = '''Copyright Notice: Hoolie explicitly owns## all rights to this toolbox. '''## self.searchKeys = ['hello', 'world', 'tool']## self.formatName = 'ArcToolbox Tool'## self.mdDateSt = '20210701'## ____________________________________________________________ def getParameterInfo(self): """Define parameter definitions""" p0 = arcpy.Parameter( displayName= 'Input First Name', name='textInput1', datatype='GPString', parameterType='Required', direction='Input')## p0.dialogReference = 'Custom tool parameter dialog/label text'## p0.pythonReference = 'Custom python reference information' p1 = arcpy.Parameter( displayName= 'Input Last Name', name='textInput2', datatype='GPString', parameterType='Optional', direction='Input')## p1.dialogReference = 'Custom tool parameter dialog/label text'## p1.pythonReference = 'Custom python reference information' p2 = arcpy.Parameter( displayName= 'Address', name='addrInput', datatype='GPString', parameterType='Optional', direction='Input')## p2.dialogReference = 'Custom tool parameter dialog/label text'## p2.pythonReference = 'Custom python reference information' p3 = arcpy.Parameter( displayName= 'Address Type', name='addrTypeInput', datatype='GPString', parameterType='Required', direction='Input') p3.filter.type = "ValueList" p3.filter.list= ['Home', 'Work', 'Other' ]## p3.dialogReference = 'Custom tool parameter dialog/label text'## p3.pythonReference = 'Custom python reference information' params = [p0, p1,p2, p3] return params 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.""" # execute some code last_name = parameters[1].valueAsText if not parameters[1].value: last_name = '' message = 'Hello world and {0} {1}!'.format( parameters[0].valueAsText, last_name) arcpy.AddMessage(message) return class byeTool(object): def __init__(self): """Define the tool (tool name is the name of the class).""" self.label = "Bye Tool" self.category = 'Tool examples' self.description = '''This tool prints a simple goodbye statement in ArcGIS Pro''' self.canRunInBackground = False## Example of available metadata tags and values for tool level## metadata within the standard ESRI "Item Description metadata style"## *Tags can be added or removed to sync with additional metadata styles*## *Metadata declared at the tool level will override toolbox level metadata*## ____________________________________________________________## self.CreaDate = '20210720'## self.CreaTime = '17120606'## self.ArcGISFormat = '1.0'## self.SyncOnce = 'TRUE'## self.ModDate = '20210701'## self.ModTime = '16591414'## self.minScale = '150000000'## self.maxScale = '5000'## self.arcToolboxHelpPath = 'D:\Help\gp'## self.summary = '''This tool prints a simple## bye statement in ArcGIS Pro'''## self.usage = '''This tool is useful in printing a simple## bye statement in ArcGIS Pro'''## self.title = 'Bye Tool: Code Sample (1)'## self.para = '''Some notes about the code sample(s)'''## self.code = '''# import the toolbox as a module## import arcpy## arcpy.ImportToolbox(r'D:\folderA\helloWorldToolbox.pyt',## r'helloworldtoolbox')#### # call the tool and return the output## result = arcpy.byeTool_helloworldtoolbox(## textInput1 #Input First Name- Type(String),## textInput2 #Input Last Name- Type(String)## )'''## self.resTitle = 'helloworldtoolbox.(Uncategorized)'## self.idCredit = '''Point of Contact (POC): Jermey Doe## Organization: Hoolie INC.## Email: Jermey.Doe@hoolie.co'''## self.useLimit = '''Copyright Notice: Hoolie explicitly owns## all rights to this toolbox. '''## self.searchKeys = ['bye', 'world', 'tool']## self.formatName = 'ArcToolbox Tool'## self.mdDateSt = '20210701'## ____________________________________________________________ def getParameterInfo(self): """Define parameter definitions""" p0 = arcpy.Parameter( displayName= 'Input First Name', name='textInput1', datatype='GPString', parameterType='Required', direction='Input')## p0.dialogReference = 'Custom tool parameter dialog/label text'## p0.pythonReference = 'Custom python reference information' p1 = arcpy.Parameter( displayName= 'Input Last Name', name='textInput2', datatype='GPString', parameterType='Optional', direction='Input')## p1.dialogReference = 'Custom tool parameter dialog/label text'## p1.pythonReference = 'Custom python reference information' params = [p0, p1] return params 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.""" # execute some logic last_name = parameters[1].valueAsText if not parameters[1].value: last_name = '' message = 'Goodbye and farewell {0} {1}!'.format( parameters[0].valueAsText, last_name) arcpy.AddMessage(message) return