The Stack Overflow podcast is back! Listen to an interview with our new CEO.
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 ...


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


12

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


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

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

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


11

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


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

You can do it in python by adding inDataset = arcpy.GetParameterAsText(0) here is that example. Understanding_script_tool_parameters Then add as a script tool. Adding_a_script_tool Or just set the model param as MLowry suggested. That is probably quicker and easier.


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

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

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

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


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


6

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 paths)' box is checked: right-click the model in the Catalog > Properties > General tab.


6

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 such as %scratchGDB% as that is the system making a decision for you. Why not create a folder with a file geodatabase called fGDB_Scratch and read\write from ...


6

The reasons for the removal of this functionality are given at What happened To Export Script Button In ArcGIS Pro? by dflater-esristaff: The ability to export from ModelBuilder to a Python script was removed from ArcGIS Pro 1.1 because it did not match user expectations to provide a one-to-one export of your model to Python. The scripts generated ...


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