arcpy.mapping.MapDocument("CURRENT")
Solved! Go to Solution.
inpoint = arcpy.Point(arcpy.GetParameter(0), arcpy.GetParameter(1)) inpointgeo = arcpy.PointGeometry(inpoint) bufferradius = arcpy.GetParameter(2) result = arcpy.SelectLayerByLocation_management("TOC layer name", "WITHIN_A_DISTANCE", inpointgeo, bufferradius, "NEW_SELECTION") layer = result.getOutput(0) rows = arcpy.SearchCursor(layer) for row in rows: do stuff with a row
arcpy.MakeFeatureLayer_management("..mygdb/mydataset/myfeatureclass", outlayer)
arcpy.Buffer_analysis('layer name in source map doc TOC', '%scratchworkspace%\out.shp', '100 Miles')
arcpy.MakeFeatureLayer_management("layer name in source map doc TOC", outlayer) rows = arcpy.SearchCursor(outlayer) for row in rows: do stuff with the row
inpoint = arcpy.Point(arcpy.GetParameter(0), arcpy.GetParameter(1)) inpointgeo = arcpy.PointGeometry(inpoint) bufferradius = arcpy.GetParameter(2) result = arcpy.SelectLayerByLocation_management("TOC layer name", "WITHIN_A_DISTANCE", inpointgeo, bufferradius, "NEW_SELECTION") layer = result.getOutput(0) rows = arcpy.SearchCursor(layer) for row in rows: do stuff with a row
Mark,
You cant access "CURRENT" within a GP Service. You're correct, its the same idea as background processing. You'd have to set explicit paths to the map document you want to build your GP Service for arcpy.Mapping around.
From your post the other day - what is your end goal?
--To use layers inside tools within your service (the use of layers to save the re-open cost on execution)
or
--To interact with layers, and map documents with the end goal of creating a jpeg or pdf which could be printed
While these ideas both use "layers", technically they go about it differently. Yes, all things equal they're all layers, but when it comes down to it:
arcpy.Mapping.Layer (http://help.arcgis.com/en/arcgisdesktop/10.0/help/index.html#/Layer/00s300000008000000/) does not equal "layers" you use in a tool (http://help.arcgis.com/en/arcgisdesktop/10.0/help/index.html#//001700000073000000)
If you goal is to use layers in a service for tool execution, your workflow is basically:
-Add the layers you want to use into your map document
-Create your script. Where your tool executes against a "layer", simple use a string inside the tool parameter with the layers name.
--Its this 1:1 match up of the layers name in the ToC and the string inside your script which makes this work
-Create a tool layer. (drag the tool into the ToC).
-Publish using "Add New Service" - look for the topic title "Geoprocessing service with a source map document" located at: http://help.arcgis.com/en/arcgisdesktop/10.0/help/index.html#/Publishing_geoprocessing_services/002v...