Delete Simulation and Results

Hi,

Does anyone know how to delete a simulation and its results using the Python API?

Thanks!

Why use Python api

@lj said in Delete Simulation and Results:

Hi,

Does anyone know how to delete a simulation and its results using the Python API?

Thanks!

Hi Lj,

the commands below should help:

import s4l_v1.document as document
sim = document.AllSimulations[0]    # access by index, starting with 0
#sim = document.AllSimulations["my_simulation"]    # access by name
sim.ClearResults()  # delete results
sim.ResetVoxels()  # delete voxels
document.AllSimulations.Remove(sim)   # remove simulation from project

Thank you @Sylvain!

@lj said in Delete Simulation and Results:

Thank you @Sylvain!

you're welcome!

I would also recommend using the auto-completion feature in the Console. For example, if you type

sim=document.AllSimulations[0]

to assign the sim variable and then sim followed by a . (dot) , you should see all the functions that you can use with this simulation object. Usually easier than trying to remember all of them 🙂

3127303b-04eb-4862-b597-5838bf435174-image.png

Yeah, I do use it. Its very helpful! I guess the mistake I was making was trying to find the delete/ remove within sim rather than document.allsimulations.

yes, that one is not very obvious indeed. A hint might be given by looking at how simulations are "added" to the project (see for example the auto-generated code when you select a simulation and click "To-Python").

That makes sense- thank you!