Search code examples
pythonpython-2.7arcpy

ArcMap 10.2: Custom ArcGIS tool.


I am trying to modify the first script and convert it into a custom ArcGIS tool. The first script takes to shapefiles and converts them to feature layers then intersects the new feature layers and finally copies the output to a ne shapefile. This portion of the script works.

The second script is suppose to be a modified version of the first script. Most of the script appears to work except for the count= int(arcpy.GetCount_management("output_features").getOutput(0)), the arcpy.AddMessage and the arcpy.AddWarning portions.

I am not sure if the script is correct for count = int(arcpy.GetCount_management("output_features").getOutput(0))

Currently the arcpy.AddMessage returns "A new feature class (the full path of the output_features) the out has been created!"

I want it to say "A new feature class 'selected_parcels' has been created!"

Furthermore, I want arcpy.AddWarning to return the number of rows in in selected_parcels. Currently I am getting an error indicating that count does not exist.

#Current code:

#Part I


try:
    userWorkspace = raw_input("What is the workspace location?")
    input_class = raw_input("What is the input feature class name?")
    select_class = raw_input("What is the select feature class name?")
    output_class = raw_input("What is the output feature class name?")

    arcpy.env.workspace = userWorkspace
    arcpy.env.overwriteOutput = True
    arcpy.MakeFeatureLayer_management(input_class,"lyr")
    arcpy.MakeFeatureLayer_management(select_class,"select_lyr")
    arcpy.SelectLayerByLocation_management('lyr','intersect','select_lyr')
    arcpy.CopyFeatures_management("lyr",output_class)
    print "A new feature class",output_class," has been created!"
except:
    print arcpy.GetMessages()

#Part II


import arcpy

arcpy.env.workspace = r"C:\Users\tpmorris\ProgramingAndScripting\Lab 5 Data\Lab 5 Data"
arcpy.env.overwriteOutput = True

input_features = arcpy.GetParameterAsText(0) 
selected_parcels = arcpy.GetParameterAsText(1)
output_features = arcpy.GetParameterAsText(2)



arcpy.MakeFeatureLayer_management("coa_parcels.shp","lyr") 
arcpy.MakeFeatureLayer_management("floodplains.shp","select_lyr") 
arcpy.SelectLayerByLocation_management('lyr','intersect','select_lyr') 
arcpy.CopyFeatures_management("lyr","selected_parcels")


count = int(arcpy.GetCount_management("output_features").getOutput(0))
arcpy.AddMessage("A new feature class" + output_features + "has been created!")
arcpy.AddWarning("There are" + count + "in the new feature class.")

Any guidance would be appreciated!


Solution

  • I believe the problem with your code is that, when you are calling arcpy.GetCount_management, you are supplying a string ("output_features") as a parameter, not your variable output_features.

    Something like this should work:

    result = arcpy.GetCount_management(output_features)
    count = int(result.getOutput(0))
    arcpy.AddWarning("There are {0} in the new feature class.".format(count))

    Good luck!

    Tom