Script Tool Working but not working correctly

514
4
12-12-2011 07:48 AM
ChrisBrannin
Occasional Contributor
Hello

I am a little confused on why my script tool is not working. I run it and it finishes with no issues but nothing happens. I have even tried to simplify it down and the same thing happens (runs and finishes with no errors but doesn't complete its task)

The tool is a simple add field and then clip to an area. Please help I am trying to get this code to work for a class project as an add on component.

import arcpy
from arcpy import env

try:

#Functions
    inTest = arcpy.GetParameterAsText(0)    
    clipArea = arcpy.GetParameterAsText(1)
    outFeature = arcpy.GetParameterAsText(2)

    arcpy.env.workspace = "S:/TallPinesGIS/Data"

# Add Field to Polygon for ranking
    arcpy.Addmessage('Adding Fields')
    arcpy.AddField_management("inTest","TEST","SHORT","2","#","#","#","NON_NULLABLE","NON_REQUIRED","#")
# Clip Features to current Project Area
    arcpy.Addmessage('Clipping features outside of project area')
    arcpy.Clip_analysis("inTest","clipArea","outFeature","#")

except:
    print arcpy.GetMessages() 
Tags (2)
0 Kudos
4 Replies
ChrisSnyder
Regular Contributor III
You need to unquote your variables. Try this:

import arcpy
from arcpy import env

try:

#Functions
    inTest = arcpy.GetParameterAsText(0)    
    clipArea = arcpy.GetParameterAsText(1)
    outFeature = arcpy.GetParameterAsText(2)

    arcpy.env.workspace = "S:/TallPinesGIS/Data"

# Add Field to Polygon for ranking
    arcpy.Addmessage('Adding Fields')
    arcpy.AddField_management(inTest,"TEST","SHORT","2","#","#","#","NON_NULLABLE","NON_REQUIRED","#")
# Clip Features to current Project Area
    arcpy.Addmessage('Clipping features outside of project area')
    arcpy.Clip_analysis(inTest,clipArea,outFeature,"#")

except:
    print arcpy.GetMessages()
0 Kudos
MathewCoyle
Frequent Contributor
You're variables cannot use quotes as this would indicate a string instead of the variable you are trying to pass.
inTest != "inTest"
0 Kudos
ChrisBrannin
Occasional Contributor
Thank you for the responses! I ran it again and got the same results. I aslo realized that I was testing it with .shp and thought that I would need to use
inTest = arcpy.MakeFeatureLayer_management(inTest)


but am still getting the same results for that as well.
0 Kudos
ChrisBrannin
Occasional Contributor
Got it! I took out the try: & except: and noticed that the AddMessage was Addmessage. Works like a charm now! Thanks again for all the help!

Cheers
Chris
0 Kudos