I am very new to Blender. I am an advanced Python user. I want to do with Blender something similar as with OpenSCAD, in case somebody here knows it. So basically I want to use Blender fully from Python scripts, the graphical interface only for visualizing the results. This means that each time I run my main.py I want Blender to be restarted and execute that script from scratch, without any memory from previous runs. Is this possible?

Of course one way to achieve this is to open a new project each time I run the script, reload the script and run it. But this is completely unpractical.

Up to now I have only found this which adds two lines


to select all objects and delete them. But there are many other things like materials, world settings, etc. etc. that would be nice to restart so I can be sure the script is doing all that I want.

  • 4
    $\begingroup$ You can open a new Blender and run your script with blender -P script.py. Is that what you want? $\endgroup$
    – scurest
    Sep 26 at 16:50
  • $\begingroup$ Have you tried invoking bpy.ops.wm.read_factory_settings() from your script? That's pretty draconian, so maybe bpy.ops.wm.read_homefile(app_template="") which restarts from your startup file. $\endgroup$ Sep 26 at 16:51
  • 1
    $\begingroup$ @scurest thanks, that is very close to what I am looking for. Please promote your comment to answer so I can accept it. $\endgroup$
    – user171780
    Sep 26 at 16:59
  • 2
    $\begingroup$ Related blender.stackexchange.com/questions/219235/… $\endgroup$
    – batFINGER
    Sep 26 at 18:56

I think I would do this by setting up my startup file so that it ran the script every time a new file was opened. I would modify my script to have a 'restart' option, possibly as a menu entry that invoked bpy.ops.wm.read_homefile(). Or I'd simply use the existing File->New->General menu entry to restart.


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.