0

I'm trying to run the MosaicToNewRaster tool as part of a python script. This is my code:

input_rasters = arcpy.GetParameterAsText(5), arcpy.GetParameterAsText(6), arcpy.GetParameterAsText(7), arcpy.GetParameterAsText(8)
output_location = "C:/Birkbeck_Python/Prog_Assign_1.gdb"
arcpy.MosaicToNewRaster_management(input_rasters, output_location, "R_Dataset", "", "",    "", "1", "", "")

I get the following error message, anybody got any ideas? It works fine when I hardcode it.

Thanks

ExecuteError: Failed to execute. Parameters are not valid. ERROR 000732: Input Rasters: Dataset '';'';'';'' does not exist or is not supported Failed to execute (MosaicToNewRaster).

2 Answers 2

2

You need to create a raster list rather than a series of paths separated by commas. Try something like the following:

input_rasters = arcpy.GetParameterAsText(0)
output_location = "C:/Birkbeck_Python/Prog_Assign_1.gdb"
arcpy.MosaicToNewRaster_management(input_rasters, output_location, "R_Dataset", "", "",    "", "1", "", "")

Then you can add a multivalue raster dataset when you produce the script tool, as follows:

enter image description here

3
  • THanks @Aaron, I tried what you said but now it's saying: 'ExecuteError: Failed to execute. Parameters are not valid. ERROR 000735: Input Rasters: Value is required Failed to execute (MosaicToNewRaster).' Any ideas?
    – Dunuts
    Jul 27, 2013 at 22:39
  • From the help page @Luke linked to: "The input raster datasets are all the raster datasets you would like to mosaic together. The inputs must have the same number of bands and same bit depth; otherwise, the tool will exit with an error message."
    – Aaron
    Jul 27, 2013 at 23:32
  • I'm 100% sure they're all the same depth etc. I can get it to work perfectly when I hardcode everthing! It's just not recognising the rasters in the workspace!
    – Dunuts
    Jul 28, 2013 at 9:59
2

You need to pass a semicolon separated string instead of a list/tuple.

input_rasters = ';'.join((arcpy.GetParameterAsText(5), arcpy.GetParameterAsText(6), arcpy.GetParameterAsText(7), arcpy.GetParameterAsText(8)))
output_location = "C:/Birkbeck_Python/Prog_Assign_1.gdb"
arcpy.MosaicToNewRaster_management(input_rasters, output_location, "R_Dataset", "", "",    "", "1", "", "")
3
  • Thanks, after I change it to the above do I use multivalue rasters in my script tool?
    – Dunuts
    Jul 27, 2013 at 22:45
  • I tried the above with a multivalue raster input and it gave me the same error as I was getting: 'ExecuteError: Failed to execute. Parameters are not valid. ERROR 000735: Input Rasters: Value is required Failed to execute (MosaicToNewRaster).' Any advice appreciated.
    – Dunuts
    Jul 27, 2013 at 22:48
  • @Dunuts: no, if you use a multivalue parameter, arcpy.GetParameterAsText(parameter number) will return a semicolon separated string
    – user2856
    Jul 28, 2013 at 1:11

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge that you have read and understand our privacy policy and code of conduct.

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