Select to view content in your preferred language

Setting Script Tool Parameters - Python in ModelBuilder

9017
18
05-11-2015 12:35 AM
NickBauer
Deactivated User

Hi All,

I am wondering if you could help with following. Essentially it relates to the following help article "Setting Script Tool Parameters" ArcGIS Help (10.2, 10.2.1, and 10.2.2)

I have a used ModelBuilder to create a geoprocessing workflow. However for part of this I need to run a script within the model to dissolve some features within a layer (the inbuilt modelbuilder geoprocessing function for this does not give me multi-part polygons, despite this being a supposed option).

Thanks in advance (Using ArcGIS 10.2)

Nick

Essentially the problem I encounter is that when I run the model ArcGIS goes in to 'not responding mode' and does not recover. I suspect there is something wrong with wither my python script or the way I am passing variables between modelbuilder and my python script?

Python Script - Dissolve2

import arcpy

arcpy.env.workspace = "C:/Data/ArcGIS/Default.gdb/Dissolve1"

inLayer = arcpy.GetParameter(0)

outLayer = "C:/Data/ArcGIS/temp/OutDisolve.shp"

arcpy.Dissolve_management(inLayer, outLayer, "Id", "","MULTI_PART", "")

arcpy.SetParameter(1, OutLayer)

I have provided screenshots below

1. A simplified view of the model

Model.JPG

InLayer.JPGOutLayer.JPG

2. Parameter Input and Output

0 Kudos
18 Replies
NickBauer1
Deactivated User

Thanks Curtis,

This is definitely helping me eliminate some issues, but I am still trying to get to the bottom of the issue I am having.

0 Kudos
SusanJones
Frequent Contributor

Your workspace is set as a folder inside of a file geodatabase,

Your output layer is specifying an output shapefile.

The data type is incompatible

Try

arcpy.env.workspace = "C:/Data/ArcGIS/Default.gdb/"

Replace

outLayer = "C:/Data/ArcGIS/temp/OutDisolve"

Susan

SusanJones
Frequent Contributor

Your workspace is set as a folder inside of a file geodatabase,

Your output layer is specifying an output shapefile.

The data type is incompatible

Try

arcpy.env.workspace = "C:/Data/ArcGIS/Default.gdb/"

Replace

outLayer = "OutDisolve"

Susan

0 Kudos
WesMiller
Deactivated User

Have you checked the "id" field to ensure there are multiple matching values in that field?

0 Kudos
SepheFox
Deactivated User

The first thing I noticed is that your workspace is set to a feature class inside a gdb, as Susan is saying. The workspace should be either a GDB or a folder.

0 Kudos
curtvprice
MVP Alum

Just to make sure it's clear for the good of the thread:

A workspace can be a folder, a geodatabase, or a feature dataset (within a geodatabase).

0 Kudos
SepheFox
Deactivated User

Actually, I didn't know it could be a dataset, so thanks for that info, but what Nick's trying to use is not clear, since his script tool dialog says the input is a shapefile, so I would think he would want his workspace to be a folder.

0 Kudos
curtvprice
MVP Alum

It should work as the current workspace does not come into play when complete paths are provided. In fact I don't see a reason to set the workspace at all in his model. (It is a simplified model he kindly provided, so there is probably more going on we don't know about.

I would avoid setting workspaces to be feature datasets unless there was a reason (ie making the code easier to read when processing data within a feature dataset. I could imagine there may be some bugs he may run into.

DarrenWiens2
MVP Alum

Just a demo of Curtis' point. The workspace environment is only used when it hasn't been overridden by a full path:

>>> arcpy.env.workspace = r'C:\junk\File_GDB.gdb'
>>> out_shape = r'C:\junk\out_shape.shp'
>>> in_shape = r'C:\junk\points.shp'
>>> arcpy.Buffer_analysis(in_shape,out_shape,"50 METERS")
<Result 'C:\\junk\\out_shape.shp'>
>>> arcpy.Buffer_analysis(in_shape,'buffer',"50 METERS")
<Result 'C:\\junk\\FILE_GDB.gdb\\buffer'>