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
2. Parameter Input and Output
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.
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
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
Have you checked the "id" field to ensure there are multiple matching values in that field?
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.
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).
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.
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.
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'>