Error in restoring the model inside the loop

Dear all,
I want to restore the model inside the loop so I can automate the extraction of the results. But when I try the following code, it gives me the error :"
fish define dataextract
loop local i(0,15)
local e0 = i * 0.01
local suf = string.build(“%0.2f”, e0)
command
model restore(“HostSoilShearingModel/Shearing_e” + suf + “.p3sav”);
@output_balldata(“HostSoilShearingData2/balldata_Shearing_e” + suf)
@output_contactdata(“HostSoilShearingData2/contactdata_Shearing_e” + suf)
endcommand
endloop
end

; execute batch
@dataextract

Error:
*** You cannot RESTORE a model from this input source (Probably a FISH command/end_command).
While processing line 137 of source GUI Console.
While executing line 136 columns 9 to 16 of source GUI Console.
While executing line 144 columns 2 to 13 of source GUI Console.
While processing line 144 of source GUI Console.

Hello @SahilW,
You cannot restore a save file in a FISH function. If you want to do batch modeling I suggest using Python like in this parameter studies example. The example is for 3DEC, but the same logic will work for PFC.

I’m facing an issue using IPython. I wrote the following lines, but an error appears. Can you help me to fix it?
import itasca as it

for i in [0.01, 0.02, 0.03, 0.04]:
filename = f"Sh25/Shearing_e{str(i)}.p3sav"
it.command(“”"
model restore model restore ‘{filename}’)

Hello @SahilW,
Can you post the python file you wrote? Remember python syntax is space sensitive when writing for loops. Just a guess but it could be something entirely different.

similar problem solution for UDEC rather than PFC without using python, responding here in case the logic is useful for others…

i have previously used python to do batch exports of data and/or plots from FLAC3D/3DEC as suggested above for PFC, but just hit this problem of trying to use model restore within a FISH command / endcommand block whilst wanting to do some batch exports from UDEC where python isnt available. I combatted it by using FISH to generate a .dat file of my required model restore and plot export commands (two different lists of plots first created for different models), and then can run that .dat outside of the FISH function. See below:

; config
local output_root = 'output'
local size_x = 1920
local size_y = 1080

; scan the working folder for files
local lines = system.directory.list('.', false, false)

; build up the generated command-file contents as a list of lines
local out_lines = list

loop foreach local fname lines

    local flen = string.len(fname)

    ; only process entries that end in ".sav"
    if flen > 4 then
        if string.sub(fname, flen - 3, 4) = '.sav' then

            local basename = string.sub(fname, 1, flen - 4)
            local outdir = output_root + '/' + basename

            ; create the output folder now
            local dir_ok = system.directory.create(outdir)

            out_lines = list.append(out_lines, "model restore '" + fname + "'")

            if string.find(fname, '_initial') # 0 then

                ; initial state - use the initial plot set
                loop foreach local pname initial_plots
                    local pline = "plot '" + pname + "' export bitmap filename '" + outdir + "/" + pname + ".png' size " + string(size_x) + " " + string(size_y)
                    out_lines = list.append(out_lines, pline)
                endloop

            else

                ; all other states - use the other plot set
                loop foreach pname other_plots
                    local pline2 = "plot '" + pname + "' export bitmap filename '" + outdir + "/" + pname + ".png' size " + string(size_x) + " " + string(size_y)
                    out_lines = list.append(out_lines, pline2)
                endloop

            endif

        endif
    endif

endloop

; write the generated command file
local out = file.open('batch_generated.dat', 'write', 'text')
file.write(out, out_lines)
file.close(out)