How do I use the Surface Volume tool in ArcMap via Model Builder, without using Python, to process a set of multiple float values in a loop, since an iterator takes integers when I implement a for loop?

See the attached image as indication.

enter image description here


You can use the Iterate Multivalue tool and add a list of floats:

enter image description here


An alternative method is to create a table and store your floats in that, 1 row per float value. Then use the Iterate Field Value iterator to drive your model. But I think @user2856 has the simplest solution.

  • the issue in here is that for both options, iterate multivalue and iterate field value it is not possible connect it to the so called "plane height" - which is the field of the tool i'd like apply multiple values to
    – Olli
    Jul 21 '20 at 15:09
  • 1
    Try parsing the output of the iterator into a Double using the Calculate Value tool, then feed that into the volume tool
    – Hornbydd
    Jul 21 '20 at 18:59
  • Thanks, thats exactly what I was looking for! :)
    – Olli
    Jul 22 '20 at 7:45

Here is the code to loop the surface volume tool. You can hard-code the paths and run this in your favourite IDE. Or un-comment the arcpy.GetParameter....stuff and turn this into a Toolbox Tool.

import sys, arcpy, traceback

arcpy.AddMessage( "Multi-Volumes for ArcGIS 10")
arcpy.AddMessage("Loop the 3D Analyist Surface Volume tools for a range of values...")

def GetValues(themessage, x):
    thevaluesatx = str(x)
    themessage = themessage.split("\n")
    thevalues = themessage[2].split("  ")
    for item in thevalues:
        thevalue = item.split("=")
        thevalue = thevalue[-1]
        thevaluesatx = thevaluesatx + "," + str(thevalue)
    thevaluesatx = thevaluesatx +"\n"
    return thevaluesatx

My_txt = r"F:\FerndaleDirtPile20190729\ferndaledirtpipe20190729demUTMvolumes.csv"
My_surface= r"F:\FerndaleDirtPile20190729\ferndaledirtpipe20190729demUTM.tif"
direction = "ABOVE"
startingplane = 4
endingplane = 10.4
z = 1
graduations = 0.25

#My_surface= arcpy.GetParameterAsText(0)
#My_txt = arcpy.GetParameterAsText(1)
#direction = arcpy.GetParameterAsText(2)
#startingplane = float(arcpy.GetParameterAsText(3))
#z = float(arcpy.GetParameterAsText(4))
#graduations = float(arcpy.GetParameterAsText(5))
#endingplane = float(arcpy.GetParameterAsText(6))

direction  = direction.upper()
f = open(My_txt,'a')
f.writelines(r"elevation, 2d_area, 3d_area, volume" + "\n")

arcpy.AddMessage("Please wait, this script is processing...")

if direction == "BELOW":
    arcpy.AddMessage("startingplane = " +str(startingplane))
    arcpy.AddMessage("endingplane = " +str(endingplane))
    while startingplane > endingplane:
        arcpy.AddMessage("Getting Results...")
        result = arcpy.SurfaceVolume_3d(My_surface, "", direction, startingplane)
        thevaluesatx = GetValues(result.getMessages(0), startingplane)
        startingplane = startingplane - graduations

if direction == "ABOVE":
    arcpy.AddMessage("Executing above...")
    x = startingplane
    while startingplane < endingplane:
        result = arcpy.SurfaceVolume_3d(My_surface, "", direction, startingplane, z)
        thevaluesatx = GetValues(result.getMessages(0), startingplane)
        print thevaluesatx
        startingplane = startingplane + graduations


arcpy.AddMessage("Finished without errors!")

except arcpy.ExecuteError: 
    msgs = arcpy.GetMessages(2) 
    #If the error is with the script, or with python, find error and report it to the screen...
    tb = sys.exc_info()[2]
    tbinfo = traceback.format_tb(tb)[0]
    pymsg = "PYTHON ERRORS:\nTraceback info:\n" + tbinfo + "\nError Info:\n" + str(sys.exc_info()[1])
    msgs = "ArcPy ERRORS:\n" + arcpy.GetMessages(2) + "\n"
  • The question specifically states "without using Python".
    – user2856
    Jul 20 '20 at 3:16

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.