35

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 ...


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 ...


13

I had the same issue a while back. It's a pretty easy fix, just use the the describe tool. Your already getting the layer name from your parameters. So all you have to do is describe the layer, find the path then merge the two. layer = arcpy.GetParameterAsText(0) desc = arcpy.Describe(layer) path = desc.path layersource = str(path) + "/" + layer That ...


13

A sample code for a script tool which will have a single check box. If a check box will be checked by a user, the tool will verify existance of a specified data file. import arcpy input_fc = r'C:\GIS\Temp\data_shp.shp' #getting the input parameter - will become a tool parameter in ArcGIS of Boolean type ischecked = arcpy.GetParameterAsText(0) #...


13

There are a couple of ways to approach this: Create a list of filter values in the parameters property. Create the list in the validation script. I prefer the second route since you have more control over what values are valid as well as extracting unique values from fields. Going the first route: Set the data type to string (as shown in your picture) ...


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

See 'Geoprocessing_data_types.pdf' in Data types for geoprocessing tool parameters To answer your specific question, I belive you would want to use a Workspace parameter which will let you specify an SDE connection file, then use filters to limit the workspace type (see screenshots in comment below).


11

Yes, you can run multiprocessing child processes from a toolbox script. Below is some code to demonstrate in a Python Toolbox (*.pyt). There are a number of "gotchas". Some (but not all) will be applicable to Python script tools in a binary toolbox (*.tbx), but I only use Python Toolboxes these days so have not tested. Some "gotchas"/tips: Make sure each ...


10

Yup, you need to use the Tool Validator. See this help link: http://resources.arcgis.com/en/help/main/10.1/index.html#/Programming_a_ToolValidator_class/00150000000v000000/ def initializeParameters(self): self.params[4].category = "Options" self.params[5].category = "Options" self.params[6].category = "Advanced" self.params[7].category = "Advanced"


10

Like Jay said, you need to add logic to test whether each optional parameter was specified and take the appropriate action (or inaction) for each case. Modifying your snippet above: #SEWER# sewer = arcpy.GetParameterAsText(0) if sewer and sewer != "#": arcpy.AddField_management(sewer, "UID", "TEXT", 10, "", "", "", "NON_NULLABLE", "", "") arcpy....


10

If you add a geoprocessing tool to a toolbar it will run immediately upon clicking it, provided it has no parameters:


10

Both are just different names for the same thing. You can see this by using the is operator: arcpy.na.CopyTraversedSourceFeatures is arcpy.CopyTraversedSourceFeatures_na will return: True Which tells you that both of these names point to the same object. Your best course of action is to pick one way of doing it in your scripts and stick with it. Just ...


9

This should work: RoadName = "'" + arcpy.GetParameterAsText(0).upper() + "'" You can also use the string module: import string RoadName = "'" + string.upper(arcpy.GetParameterAsText(0)) + "'"


9

This was a simple question that had found difficult to answer. I searched through the Esri documentation, which is usually very thorough, but just overlooked it. I wanted to share my answer here in a concise manner. In the Parameters dialog, set up a parameter, and set its direction to "output". Set the type to "Derivative" if applicable. In the script, ...


9

Change the "Obtained from" property for the input to the shapefile parameter.


8

I assume that you've added the Python script to the model by first adding the Python script to the toolbox, setting the script input through the Parameters tab. In the Parameters tab you can add new parameters for the script output. To do this simply change: the Direction in the Parameter Properties to Output; the Data Type depending on what the Python ...


7

Under your Fields to Choose option, change it to Field instead of Field Mappings. That will give you a list of the feature layer fields.


7

You're not really supposed to do this, but you could open a cursor in your validator's updateParameters method. if self.params[0].value and arcpy.Exists(self.params[0].value): value_set = set(row.getValue('COL_NAME') for row in arcpy.SearchCursor(str(self.params[0].value)))) self.params[1].filter.list = sorted(value_set) This ...


7

Try setting the tool validator class code to this: 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.""" self.params = arcpy.GetParameterInfo() def initializeParameters(self): ...


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

Try adding a print useDefault immediately after you set it to see what is returned. I have a suspicion (without testing) that it may be returning 'True'(or 'False') rather than 'true' (or 'false'). Also, arcpy.GetParameterAsText() always returns a string so you need to test for the String of 'True'(or 'False'). If you use arcpy.GetParameter() then you ...


7

Your issue is arising due to the use of a comma as the decimal mark. It may help to understand that in your script you are not converting a double into a float, you are converting a string into a float. The string, when a comma is used as the decimal mark, is invalid. I would make use of the Replace method here to ensure that a decimal point is used in the ...


6

Rather than suggest modifications to your script, I am going to recommend that you consider adopting Esri's PythonTemplate which includes this functionality and more. The blog posting has since been removed but I'll leave the link in case it is ever put back. The code for Esri's template.py appears below. #-------------------------------- # Name: ...


6

When you call a script tool it behaves just like any other geoprocessing tool you call from Python. No messages are automatically added to the console (unless there is an unhandled exception). What you want to do is use arcpy.GetMessages() and arcpy.AddMessage, AddWarning, AddError, etc. after calling the script tool as described in the help.


6

I'm not entirely sure if I understand your question, it leaves itself open to a few interpretations. The Python itself is slow: You don't need to do any conversion. Just use the standard profiling tools the Python Standard Library offers to get some insight as to what's running slow. The bookkeeping of the Geoprocessing tool is slow: If the set up and tear ...


6

You can do this using 2 os.path functions (splitext and basename): import os os.path.splitext(os.path.basename(r'C:\user\shapefiles\polygon.shp'))[0] # returns 'polygon'


6

As the name GetParameterAsText() indicates, or the documentation states, the value will be converted to text, or like we call it: a string. Gets the specified parameter as a **text** string by its index position from the list of parameters. So, if the user enteres coordinates, such as 35.5432 then the tool would get understand those as '35.5432', a string....


6

Extending @PolyGeo's answer, running this snippet from the command line and from a toolbox with a single parameter set as "boolean, optional" will give slightly different returns. import arcpy useDefault = arcpy.GetParameterAsText(0) # report to Arcgis message queue arcpy.AddMessage(useDefault) arcpy.AddMessage(type(useDefault)) # report to shell console ...


6

Looks like it is converting value NULL to float variable. Add an extra if condition to evaluate the variable before performing the conversion: e.g. if myValue[1] <> None: # ignoring null, continue on or if myValue[1]: # ignoring null, continue on


6

Tkinter is not compatible with any version of Arcmap desktop. As a script you are running pure python, and not using the ArcMap desktop application at all, which is why you are seeing different behavior. Esri has determined that tkinter and Arcmap desktop conflict in their messaging designs and they will not resolve the conflict, so tkinter is not supported ...


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