New To Python Script use in ArcGis 10.  Topo to Raster Errors???

1981
4
02-19-2011 09:48 AM
CharlesGant
New Contributor III
I'm new to exporting a model to python script.  I'm trying to automate the generation of maps.  I have a toolbox with a tool in it called PrecipMap.  I need to be able to run that tool automatically.  I exported the script and tried to run.  I get this error.

  File "R:\PrecipMap\PrecipMapping.py", line 44, in <module>
    arcpy.gp.TopoToRaster_sa("R:\\PrecipMap\\DailyPrecip.shp pcpn PointElevation
", TopoToR_shp2, "0.003", "R:\\Shapefiles\\Other Shapefiles\\MEGCWA.shp", "20",
"", "", "ENFORCE", "CONTOUR", "40", "", "1", "0", "", "", Output_stream_polyline
_features, Output_remaining_sink_point_features, Output_diagnostic_file, Output_
parameter_file)
  File "C:\Program Files\ArcGIS\Desktop10.0\arcpy\arcpy\geoprocessing\_base.py",
line 474, in <lambda>
    return lambda *args: val(*gp_fixargs(args))
arcgisscripting.ExecuteError: ERROR 000622: Failed to execute (Topo to Raster).
Parameters are not valid.
ERROR 000628: Cannot set input into parameter extent.

So it says the parameters are not set.  This all works just fine in Model Builder.  Can someone help me?  I have tried to set the parameters but I'm not really sure what I'm doing or what the parameters even are.  Everything in the topo to raster tool that is not "optional" is defined.  Any help would be greatly appreciated.
Tags (2)
0 Kudos
4 Replies
MichaelStead
Occasional Contributor III
I think you have just exported the scripting behind the tool, but you need to be add your inputs as it looks like it is using a bunch of placeholders and maybe you intentionally hardcoded a couple of layers (or maybe they were just exported that way). Are you just right clicking on it in the toolbox and hitting run? Your script needs to have some lines defining sys.argv() to variable names that are used through your script and when you import the script into the toolbox you need to define these variables in the parameters tab.
0 Kudos
CharlesGant
New Contributor III
Yeah I just use the run option in the toolbox to run the tool.  I take it that it's not that simple for the python script.  So do I have to add a script to the toolbox by right click on he toolbox and clicking add toolbox?  I tried that but I really don't know what I'm doing.  You have to add a python script, is that the script I just exported?  Also I'm unsure how to add the parameters and what the parameters even are.  Sorry for my ignorance but I just have never done this before and I'm just clueless.  Could you maybe describe how to do it?  I know how to auto export the maps once I get the model to run through python. 

For reference here is what I do on a normal basis to run this model.  I just double click it to run it.  When finished I open my .mxd file and export the map.  All I did what open the model in modelbuilder and export the python script.  Would it help to see the script?  I can post if so.  Any help would be greatly appreciated.  Thank you so much!
0 Kudos
CharlesGant
New Contributor III
Here is the script that was exported in model builder.

# ---------------------------------------------------------------------------
# sample.py
# Created on: 2011-02-19 11:28:49.00000
#   (generated by ArcGIS/ModelBuilder)
# Description:
# ---------------------------------------------------------------------------

# Import arcpy module
import arcpy

# Check out any necessary licenses
arcpy.CheckOutExtension("spatial")


# Local variables:
MEG_counties_shp__2_ = "R:\\Shapefiles\\Other Shapefiles\\MEG_counties.shp"
rr3precip_csv = "W:\\gistemp\\rr3precip.csv"
DailyPrecip_layer = "DailyPrecip_layer"
DailyPrecip_shp = "R:\\PrecipMap\\DailyPrecip.shp"
TopoToR_shp2 = "R:\\ArcGIS\\Default.gdb\\TopoToR_shp2"
DailyPrecip_img = "R:\\PrecipMap\\DailyPrecip.img"
DailyPrecip100_img = "R:\\PrecipMap\\DailyPrecip100.img"
DailyPrec100 = "R:\\PrecipMap\\DailyPrec100"
DailyPrecipcontour_shp = "R:\\PrecipMap\\DailyPrecipcontour.shp"
Output_stream_polyline_features = ""
Output_remaining_sink_point_features = ""
Output_diagnostic_file = ""
Output_parameter_file = ""

# Process: Make XY Event Layer
arcpy.MakeXYEventLayer_management(rr3precip_csv, "lon", "lat", DailyPrecip_layer, "", "")
print 'Make XY Event Layer Done'
# Process: Copy Features
arcpy.CopyFeatures_management(DailyPrecip_layer, DailyPrecip_shp, "", "0", "0", "0")
print 'Copy Features Done'
# Process: Topo to Raster
arcpy.gp.TopoToRaster_sa("R:\\PrecipMap\\DailyPrecip.shp pcpn PointElevation", TopoToR_shp2, "0.003", "R:\\Shapefiles\\Other Shapefiles\\MEGCWA.shp", "20", "", "", "ENFORCE", "CONTOUR", "40", "", "1", "0", "", "", Output_stream_polyline_features, Output_remaining_sink_point_features, Output_diagnostic_file, Output_parameter_file)
print 'Topo To Raster Done'
# Process: Clip
arcpy.Clip_management(TopoToR_shp2, "-91.407437 33.650117 -87.970738 36.630955", DailyPrecip_img, MEG_counties_shp__2_, "", "ClippingGeometry")
print 'Clip Done'
# Process: Single Output Map Algebra
arcpy.gp.SingleOutputMapAlgebra_sa("100 * [DailyPrecip.img] ", DailyPrecip100_img, "R:\\PrecipMap\\DailyPrecip.img")
print 'Map Algebra Done'
# Process: Int
arcpy.gp.Int_sa(DailyPrecip100_img, DailyPrec100)
print 'Int Done'
# Process: Raster to Polygon
arcpy.RasterToPolygon_conversion(DailyPrec100, DailyPrecipcontour_shp, "SIMPLIFY", "VALUE")
print 'Raster To Polygon'

I added the "print" commands in there so I could track where the errors where happening.
0 Kudos
CharlesGant
New Contributor III
Its Fixed.  I Figured it out, finally.
0 Kudos