1

I have a problem to get the code below running as a python script tool in ArcGis 10.2.2. I always get this error Message: AttributeError: ResultObject: Get attribute save not found
The tool help clearly says that there is a .save function. What am I doing wrong?

# Import arcpy module
import arcpy


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

inRaster = arcpy.GetParameterAsText(0)
DGM = arcpy.Raster(inRaster)

# Process: Fill
Fill_DGM = arcpy.gp.Fill_sa(DGM, "Fill_DGM", "")
Fill_DGM.save("F:/Desktop/test/Filled")
  • Try arcpy.Raster(dgm) – FelixIP Oct 27 '16 at 18:27
  • I already tried this, just forgot to add it to the code. Still not Working. – Max2603 Oct 27 '16 at 18:53
  • Try replacing gp thing with these 2 lines: from arcpy.sa import * and Fill_DGM =Fill_sa(DGM) – FelixIP Oct 27 '16 at 19:12
  • I had to replace arcpy.gp.Fill_sa(...) WITH Fill(...) otherwise arcpy doesn't recognize it. After this I get an TypeError: Fill() takes at most 2 arguments (3 given). So I just gave 2 arguments and got these: ExecuteError: ERROR 000875: Output surface raster: Workspace\Fill_dgm11's workspace is an invalid output workspace. ERROR 000581: Invalid parameters. I really don't get why this isn't working. – Max2603 Oct 27 '16 at 19:32
  • You need 1 parameter, the way I mentioned it in my 2nd comment. – FelixIP Oct 27 '16 at 19:40
1
# Import arcpy module
import arcpy
from arcpy.sa import * 


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

inRaster = arcpy.GetParameterAsText(0)
DGM = arcpy.Raster(inRaster)

# Process: Fill
Fill_DGM = Fill(DGM)
Fill_DGM.save("d:/scratch/Filled")

enter image description here

  • I just started writing a new script and now it works. Thanks for your help. – Max2603 Oct 27 '16 at 21:44
1

I realise this already has an accepted answer, but for the benefit of other users, here is why your code in its original form failed.

Your code failed because you were calling a save function on a Result object. Results objects do not have a save function. They have a saveToFile function. This saves information about tool execution, parameters, messages and output. This is not what you intended to do.

This would have sufficed:

arcpy.env.workspace  = r"c:\scratch.gdb"
Fill_DGM = arcpy.gp.Fill_sa(DGM, "Fill_DGM", "") #this creates a raster called FILL_DGM in the specified workspace.

Things to note:

  • The variable Fill_DGM above is a Result object
  • Fill_DGM.getoutput(0) # this returns full path to FILL_DGM raster: c:\scratch.gdb\FILL_DGM
  • No need for FILL_DGM.save(path_to_disk) # this would fail as explained above.
  • tools accessed via arcpy.sa.InsertToolNameHere return Raster Objects whereas tools accessed via arcpy.gp.insertToolNameHere_sa return Result Objects.
  • The type of object returned dictates which functions are available to you.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.