I'm trying to streamline contour production with a script tool. Typically we make the contours to bring into AutoCAD Map where we need the "Elevation" and "Layer" fields populated so they import correctly.
Basic steps in the tool:
-create a focal statistics raster
-contour the Focal Stats raster
-add CAD fields
-calculate the contour values to the "Elevation" field that Auto CAD recognized
-Calculate destination CAD Layers (intermediate or index)
I'm throwing an error when I try to do arcpy.SelectLayerByAttribute_management at the end of the script below. the error states that "Parameters are not valid.The value cannot be a feature class".
OK. so if I can't use a Feature Class, what function should I use instead that can accept a FC input?
#Import stuff
import os
from arcpy import env
from arcpy.sa import *
#where am I saving?
path = (str(arcpy.GetParameterAsText(0)))
#What layer are we using ?
mxd = arcpy.mapping.MapDocument("CURRENT")
ras1= arcpy.GetParameterAsText(1)
#name of contour FC or shp
fc_out= arcpy.GetParameterAsText(2)
#zfactor
z=arcpy.GetParameterAsText(3)
#contour interval in units of z factor
interval=arcpy.GetParameterAsText(4)
#Focal Statistics Raster (hopefully this is just memory and goes away....confirm this later)
focalras=FocalStatistics(ras1, NbrCircle(3, "CELL"),"MEAN", "NODATA")
#do teh contour
Contour(focalras,str(path)+"\\"+str(fc_out),interval,0,z)
#Add CAD Fields
if ".gdb" in path:
try:
#Add CAD Fields
arcpy.AddCADFields_conversion(str(path)+"\\"+str(fc_out),"ADD_ENTITY_PROPERTIES","ADD_LAYER_PROPERTIES","NO_TEXT_PROPERTIES","NO_DOCUMENT_PROPERTIES","NO_XDATA_PROPERTIES")
except:
# If an error occurs while running a tool print the message
print arcpy.GetMessages()
#Calculate attributes in new contour FC - still working on this.....
contours = str(path)+"\\"+str(fc_out)
#copy "Contour" field to newly added "Elevation" CAD field
arcpy.CalculateField_management(contours, "Elevation", '!Contour!', "PYTHON_9.3")
#--------------WORKS FINE UP TO HERE------------
#Populate Indedx Contour layer name
arcpy.SelectLayerByAttribute_management (contours, "NEW_SELECTION", "mod(Contour,10)=0")
arcpy.CalculateField_management ( contours, "Layer", "\"ETOPO-IND\"", "PYTHON_9.3")
#Populate Intermediate Contour layer name
arcpy.SelectLayerByAttribute_management (contours, "NEW_SELECTION", "mod(Contour,10)>0")
arcpy.CalculateField_management( contours , "Layer", "\"ETOPO-INT\"", "PYTHON_9.3")
else:
print "SHP output - no CAD fields added"