33

The two are very, very close in functionality but not completely equivalent. Common to both Includes a set of tools with a unique alias for identification Can call from arcpy Get a Geoprocessing tool dialog (essentially a full UI) for free for each tool Can keep all Python code in one file (embedding tool source in TBX, holding all the implementation in ...


17

Have a look at this thread on the ArcGIS forum. Basically just use standard python modules or a package structure and import your tools into the python toolbox. Something like: # \--SomeDir # | toolbox.pyt # \--toolpackage # | __init__.py # | script_a.py # | script_b.py #---------------------------- #The .pyt file #-------...


15

The help section titled Comparing custom and Python toolboxes has a pretty good comparison of why you might choose one over the other, although I'd be curious to hear "real world" advantages/disadvantages from those experienced in creating Python Toolboxes. One clear disadvantage that I read is the inability to mix/match models & scripts in a Python ...


15

I can see that the help text is defined with the classes self.description attribute. This is where you are going wrong. In the help page Documenting a tool in a Python toolbox it says: For Python toolboxes, the documentation for the toolbox and tools are stored in .xml files that are associated with the toolbox and tools by name. The help for each tool ...


14

I found this possibility, https://stackoverflow.com/questions/1517038/python-refresh-reload The one caveat is that if you have any variables assigned to the module, they will need to be assigned again. But as you have it written above, you could do this: import supporting_module def execute() reload(supporting_module) ... This way every time you ...


11

My number one reason for leaning towards python toolboxes is for version control and source code management (see Applying version control to ArcGIS Models), followed very closely by being able to use a code editor/IDE with tab completion, regular expressions, snippet libraries, etc. However as Ryan Dalton notes, by doing so you lose the ability to use Model ...


11

You can define messages for each parameter by following these steps: Open ArcCatalog and highlight the Script in the catalog tree Select the Description tab Click the Edit button Click the down arrow next to each parameter and type in a message Finally, save edits by clicking the Save button When a users clicks within a script parameter now they will see ...


10

If I understand correctly, you want to add Help texts to your functions. That can be done by right-clicking your tool from the toolbox window and click Item description and then Edit at the top. It'll allow you to add a description for each parameter, which will show up in the help section when clicking the parameter. If you are in Arcmap 10.0 (at least ...


10

This from ESRI: Your existing toolboxes, models, and scripts can be reused in ArcGIS Pro. However, if you use arcpy.mapping, you may need to make adjustments to work with project files (.aprx) and maps, instead of map documents (.mxd). In addition, ArcGIS Pro uses Python 3, so it is possible that you may need to make some changes to your scripts. There ...


10

This may not be the cause for everyone, but I've identified at least one set of triggers. Run Python toolbox tool from ArcCatalog Geoprocessing history is on and includes a result from #1. When starting a new ArcCatalog session, no geoprocessing windows are open initially (such as ArcToolbox window, Python window, Results window). If the above are all true,...


8

You can set the value of the parameter to the values you want to be checked, at least when using a Python Toolbox. The same should be true for your case. For example: def getParameterInfo(self): p = arcpy.Parameter() p.datatype = 'String' p.multiValue = True p.name = 'test' p.displayName = 'Test' p.parameterType = 'Required' p....


8

Farid Cher's answer is partially correct. You can use the Progressor to 'catch' a cancel event from within a Python script, and you can also do whatever cleanup necessary as well, if you enclose the call within a try ... except clause. For example, a python toolbox: import arcpy import time class Toolbox(object): def __init__(self): self....


7

I was trying to do the same thing and found that you can accomplish this indirectly by setting the following error message in the updateMessages(self) function of the ToolValidator class. It's not ideal, since "optional" will still appear next to the parameter label in the toolbox, but instead of putting the usual error icon of a red hexagon with a big X in ...


7

Change the updateParameters as follows: 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.""" if parameters[0].value: if not parameters[1].altered: fields = [f for f in arcpy....


7

This help topic should get you started -- basically you embed your toolbox in a Python package and install it in your local Python installation. Then your tool should show up automatically under system toolboxes.


7

Python Toolbox: If your script is in a Python Toolbox, you can use a Value Table (GPValueTable). def getParameterInfo(self): param0 = arcpy.Parameter( displayName='Elevation and Temperature', name='in_features', datatype='GPValueTable', parameterType='Required', direction='Input') param0.columns = [['Long', ...


7

This can be done in ArcPy when you are Defining a tool in a Python toolbox by using the canRunInBackground property: If canRunInBackground is unset or set to True, the tool will respect the current Background Processing setting in the Geoprocessing Options dialog. If set to False, the tool will always run in the foreground, overriding the ...


7

When you click "Run" or call python mytoolbox.pyt, your code does not do anything other than define the classes and import some modules. You haven't actually told python to run the tool. The best way to run your tool is using arcpy.ImportToolbox from another script or from the python prompt as per PolyGeo's answer. However, what I sometimes do for ...


6

The code example below is from the ArcGIS 10.1 Help page called Defining parameters in a Python toolbox which you have mentioned in your Question. I think the step you have overlooked is the last one where you need to specify a polygon feature class or layer file (*.lyr). The example code references a layer file called Fire_Station.lyr. def ...


6

I spoofed up a Python script of 1 parameter and wired it into toolbox and this is how I got it to check a FeatureClass input: import arcpy class ToolValidator(object): """Class for validating a tool's parameter values and controlling the behavior of the tool's dialog.""" def __init__(self): """Setup arcpy and the list of tool parameters.""" ...


6

I think it may be as simple as changing this line: describe = arcpy.Describe(parameters[0].value) or maybe describe = arcpy.Describe(parameters[0].valueAsText)


6

Yes you can, you could do it by adding a global variable that keeps track of your clicks. For example: class ToolClass2(object): """Implementation for Test_addin.tool (Tool)""" def __init__(self): self.enabled = True self.shape = "NONE" global clickCount clickCount = 0 def onMouseDownMap(self, x, y, button, shift): global clickCount ...


6

Python Toolboxes rely upon the Geoprocessing Framework provided by the applications of ArcGIS for Desktop to generate their tool dialogs. I am not aware of any documentation that suggests that they will work standalone in a Python IDE such as PyScripter, unless you are importing them into another Python script using a syntax like: arcpy.ImportToolbox(r"C:\...


6

Your toolbox will not work properly unless you change the class name to Toolbox as described in the help: To ensure the Python toolbox is recognized correctly by ArcGIS, the toolbox class must remain named Toolbox. Once I made that change, your tool opened correctly: A couple more comments are: you are passing the parameters list to your arcpy.SomeTool ...


5

Defining Parameters gives template code for creating parameters and settings such as multivalue, input/output, filtering results (only show integer fields, txt files) name, etc. Data types explains all the different data types that parameters can take. In order to set your parameter, you'll need to use the keyword. Personally, I have a list of the most ...


5

Here is a different and more robust way than I suggested before. I haven't used this module myself, but I think it would solve your problem: Python Module Reloader This library implements a dependency-based module reloader for Python. Unlike the builtin reload() function, this reloader will reload the requested module and all other modules that are ...


5

The code you require is: def updateParameters(self): """Modify the values and properties of parameters before internal validation is performed. This method is called whenever a parameter has been changed.""" if self.params[0].value: fcs = self.params[0].value.exportToString() spl = fcs.split(";") desc = arcpy....


5

Even though you may have your answer, here was my take on it based on what I thought you were doing. Param 1 = Input GDB Param 2 = Input FC (multivalue) Param 3 = Input Fields (multivalue) Validator code def updateParameters(self): """Modify the values and properties of parameters before internal validation is performed. This method is called ...


5

The simplest option is to have your execute method call a function instead of doing the actual processing. This makes it easily callable by any tool. class Foo(object) def __init__(self) #stuff def getParameterInfo(self): # list parameters for UI tool def execute(self, parameters, messages) somefunc(parameters[0].value, ...


5

One thing I have noticed (with both add-ins or custom script tools/PYT's) is that when ArcMap or Catalog load, it will instantiate the classes contained within these custom tools as the application is loaded. I do not think these start a new instance of the class when the tool is ran (unless you refresh the PYT), but maybe I am wrong. Haven't tested this ...


Only top voted, non community-wiki answers of a minimum length are eligible