Quantcast
Channel: Forums - Python
Viewing all articles
Browse latest Browse all 2485

Modifying Python script to work in a toolbox

$
0
0
I am new to python scripting and began by creating a specific tool. The clip works well in either PythonWin 2.7 or ArcToolbox 10.1. Now, I want to modify the script for any feature class. How would I modify the script to input/clip/output any feature class? GetParameterAsText? Then, I intend to add the script to a toolbox. The script is as follows:

Quote:

#Import system modules
import arcpy
from arcpy import env

#Workspace
env.workspace = "E:\User\MillageCode"

#Variables
input = "Sales_2006.shp"
clip = "EagleHarborSales_temp.shp"
output = "Output_temp5.shp"

#Clip the Sales_2006 shapefile to the EagleHarborSales_temp shapefile
arcpy.Clip_analysis(input, clip, output)

#Info
print arcpy.GetMessages()
Thanks!

So, I have modified the Python script to include the GetParameterAsText function. But, I receive an error code that statues values are not defined for the input, clip, and output. The code now reads:

Quote:

#Import modules
import arcpy, os, sys
from arcpy import env

#Workspace
arcpy.env.workspace = arcpy.GetParameterAsText(0)

#Variables
input = arcpy.GetParameterAsText(1)
clip = arcpy.GetParameterAsText(2)
output = arcpy.GetParameterAsText(3)

#Clip
arcpy.Clip_analysis(input, clip, output)

#Info
print arcpy.GetMessages()
Any suggestions on why the script errors out?

Viewing all articles
Browse latest Browse all 2485

Trending Articles