14
votes
Accepted
Choosing string from dropdown list rather than typing it into Python script tool?
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 ...
11
votes
Accepted
Can multiprocessing with arcpy be run in a script tool?
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 ...
11
votes
Adding output parameter to Python script tool?
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 ...
10
votes
Accepted
Using dot notation vs underscores when calling ArcPy functions?
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 ...
9
votes
Accepted
ArcGIS Python Script Tool Field Name Drop Down?
Change the "Obtained from" property for the input to the shapefile parameter.
8
votes
Accepted
Setting input parameter to be float for Python script tool?
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 ...
7
votes
Accepted
Getting shapefile name with ArcPy code?
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'
7
votes
Accepted
Setting up Drop-Down list in Parameters of Python script tool?
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."""...
7
votes
Accepted
Does arcpy.GetParameterAsText() have a data type?
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 ...
7
votes
Accepted
Getting multiple value pairs as Python Script tool parameter?
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 ...
7
votes
Using Boolean parameters in Python Script Tool of ArcPy?
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').
...
7
votes
Accepted
7
votes
Accepted
Extract values from a field to a list in Python (arcpy)
Your code looks a bit complicated. Perhaps your problem is the paths. Use the r (raw) syntax for the paths and list comprehension. Also you cant set arcpy.env.workspace to a shapefile. You can set it ...
6
votes
Accepted
Convert a Toolbox (.TBX) to a Python script (.PY)?
For third party toolboxes, there will either be an associated python script or the script will be embedded. Check the properties of the tool to see if there is a source script file. If embedded, ...
6
votes
Convert a Toolbox (.TBX) to a Python script (.PY)?
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 ...
6
votes
Accepted
Writing ArcGIS Python Script Tool?
I can see a couple of things you're missing in your script tool. You need to change the mxd parameter string (the unicode object mentioned in your traceback) to a map document object.
mxd = arcpy....
6
votes
Using Boolean parameters in Python Script Tool of ArcPy?
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
...
6
votes
Accepted
TypeError in Script Tool
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, ...
6
votes
ArcGIS crashing with Tkinter?
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 ...
6
votes
Accepted
Python script into model
Check 2 things:
Is the script imported in the script tool? Right-click it in the Catalog > Import Script.
Also, in the Model properties, make sure the 'Store relative pathnames (instead of absolute ...
6
votes
Accepted
Clear the Scratch.gdb
If you want to simply overwrite existing tables then set overwrite to be true at the beginning of your script as such:
arcpy.env.overwriteOutput = True
Personally I don't use those system variables ...
6
votes
Accepted
Problems with for iteration in arcpy
In your script, calculate field will compute the values of group for ALL the row (or the selected rows if you used a layer) at each iteration. Therefore the GROUP values for all rows are overwritten ...
6
votes
Accepted
Run arcpy-script as geoprocessing tool
with regards to adding layers to the active map, the gp framework logic is like this: once a gp tool completes it's processing (aka: script execution) the gp framework iterates over all output ...
5
votes
Syntax error using ArcPy Spatial Analyst module in Python
Your Try: statement is capitalised, it should be lower case - try:
5
votes
Accepted
Making list of MXDs from multi-value parameter in ArcPy?
To create a multi-value input of MXD files in a tool dialog and create a Python list from them you can do the following:
Write a short script like:
import arcpy
mxdString = arcpy....
5
votes
Accepted
MakeFeatureLayer_management where_clause input by the user
You should create a new parameter of the SQL Expression data type and then set the Obtained from option to point to the feature class parameter. This will let user see all the attributes of the ...
5
votes
Using Python new line (\n) with ArcGIS geoprocessing progress dialog?
I just created a simple Python script tool with no parameters using ArcGIS 10.3 for Desktop by adding the script below to a toolbox.
import arcpy
fc = r"C:\temp\abc.shp"
arcpy.AddMessage(fc + "\n")
...
5
votes
Accepted
ArcGIS python script validation to update text based on list?
Instead of
if self.params[0].altered:
try
if self.params[0].value:
I just tested and that seemed to work as you are hoping for. The .altered and .hasBeenValidated properties are super useful, but ...
5
votes
Incorporating several Python script tools into one tool and have user input determine section of script run?
Something like this might work
import arcpy
arcpy.env.workspace = "C:\\Buffers.gdb"
InPut = arcpy.GetParameterAsText(0)
Situation = arcpy.GetParameterAsText(1)
if Situation == 'Situation A':
...
5
votes
Accepted
ArcToolbox Date default to today
You have to modify validation script, e.g.:
import arcpy, datetime
class ToolValidator(object):
"""Class for validating a tool's parameter values and controlling
the behavior of the tool's dialog....
Only top scored, non community-wiki answers of a minimum length are eligible
Related Tags
python-script-tool × 454arcpy × 400
parameters × 66
arcmap × 58
arcgis-desktop × 46
tool-validation × 45
arcgis-pro × 41
arcgis-10.2 × 38
modelbuilder × 35
arcgis-10.3 × 26
python × 20
arcgis-10.1 × 19
arcgis-10.0 × 16
cursor × 13
python-addin × 13
field-calculator × 12
python-toolbox × 11
spatial-analyst × 9
arctoolbox × 8
arcgis-server × 7
fields-attributes × 7
python-2.7 × 7
geoprocessing-service × 7
pyqgis × 6
shapefile × 6