Reboot Blender Addon

Hi, this simple addon is very useful for addons devs.
we tire of restarting Blender to ensure the changed code works.
basically this addon will shutdown & restart blender automagically.
Note that it will not save anything. it will simply shut down & restart Blender.

Huge thanks to saidenka Blender-Scramble-Addon
as I found this function whilst translating his tools.
Enjoy.


# Add-on information
bl_info = {
	"name" : "Reboot",
	"author" : "(saidenka) meta-androcto",
	"version" : (0,1),
	"blender" : (2, 7),
	"location" : "File Menu",
	"description" : "Reboot Blender without save",
	"warning" : "",
	"wiki_url" : "",
	"tracker_url" : "",
	"category" : "System"
}


import bpy
import os, sys
import subprocess


class RestartBlender(bpy.types.Operator):
	bl_idname = "wm.restart_blender"
	bl_label = "Reboot Blender"
	bl_description = "Blender Restart"
	bl_options = {'REGISTER'}
	
	def execute(self, context):
		py = os.path.join(os.path.dirname(__file__), "console_toggle.py")
		filepath = bpy.data.filepath
		if (filepath != ""):
			subprocess.Popen([sys.argv[0], filepath, '-P', py])
		else:
			subprocess.Popen([sys.argv[0],'-P', py])
		bpy.ops.wm.quit_blender()
		return {'FINISHED'}






def menu_func(self, context):
    layout = self.layout
    layout.separator()
    layout.operator(RestartBlender.bl_idname, icon="PLUGIN")
    layout.separator()




def register():
    bpy.utils.register_module(__name__)


    bpy.types.INFO_MT_file.prepend(menu_func)




def unregister():
    bpy.utils.register_module(__name__)


    bpy.types.INFO_MT_file.remove(menu_func)


if __name__ == "__main__":
    register()

1 Like

I sort of do the same with the command line option --python my_script.py

Thks @Meta-Androcto, always a good idea!
Needed absolutely when you code…Congrats.

Sigh, Why did I think this said Robot Blender Addon? :rolleyes: I must be stupid today.

ctdabomb,
that’s a whole different addon. :wink:

Hy Meta-Androcto!
Do you plan a 2.80 revival for the reboot addon?
This would be very handy!

I tried fix it by myself: it works, but the exit quit menu pops up after some changes in the text editor?

# Add-on information
bl_info = {
	"name" : "Reboot",
	"author" : "(saidenka) meta-androcto",
	"version" : (0,1),
	"blender" : (2, 80, 0),
	"location" : "File Menu",
	"description" : "Reboot Blender without save",
	"warning" : "",
	"wiki_url" : "",
	"tracker_url" : "",
	"category" : "System"
}


import bpy
import os, sys
import subprocess


class RestartBlender(bpy.types.Operator):
	bl_idname = "wm.restart_blender"
	bl_label = "Reboot Blender"
	bl_description = "Blender Restart"
	bl_options = {'REGISTER'}
	
	def execute(self, context):
		py = os.path.join(os.path.dirname(__file__), "wm.console_toggle.py")
		filepath = bpy.data.filepath
		if (filepath != ""):
			subprocess.Popen([sys.argv[0], filepath, '-P', py])
		else:
			subprocess.Popen([sys.argv[0],'-P', py])
		bpy.ops.wm.quit_blender()
		return {'FINISHED'}


def menu_func(self, context):
    layout = self.layout
    layout.separator()
    layout.operator(RestartBlender.bl_idname, icon="PLUGIN")
    layout.separator()


def register():
  bpy.utils.register_class(RestartBlender)  
  bpy.types.TOPBAR_MT_file.prepend(menu_func)
 
def unregister():
     bpy.utils.unregister_class(RestartBlender)   
     bpy.types.TOPBAR_MT_file.remove(menu_func)
     
if __name__ == "__main__":
    register()    

hi, if you turn off prompt for quit in user prefs it should be ok.
I added prompt for quit button in ui not sure if it’s useful.

# Add-on information
bl_info = {
	"name" : "Reboot",
	"author" : "(saidenka) meta-androcto",
	"version" : (0,1),
	"blender" : (2, 80, 0),
	"location" : "File Menu",
	"description" : "Reboot Blender without save",
	"warning" : "",
	"wiki_url" : "",
	"tracker_url" : "",
	"category" : "System"
}


import bpy
import os, sys
import subprocess


class RestartBlender(bpy.types.Operator):
	bl_idname = "wm.restart_blender"
	bl_label = "Reboot Blender"
	bl_description = "Blender Restart"
	bl_options = {'REGISTER'}
	
	def execute(self, context):
		py = os.path.join(os.path.dirname(__file__), "wm.console_toggle.py")
		filepath = bpy.data.filepath
		if (filepath != ""):
			subprocess.Popen([sys.argv[0], filepath, '-P', py])
		else:
			subprocess.Popen([sys.argv[0],'-P', py])
		bpy.ops.wm.quit_blender()
		return {'FINISHED'}


def menu_func(self, context):
    layout = self.layout
    layout.separator()
    layout.operator(RestartBlender.bl_idname, icon="PLUGIN")
    layout.separator()
    prefs = context.preferences
    view = prefs.view
    layout.prop(view, "use_quit_dialog")


def register():
  bpy.utils.register_class(RestartBlender)  
  bpy.types.TOPBAR_MT_file.prepend(menu_func)
 
def unregister():
     bpy.utils.unregister_class(RestartBlender)   
     bpy.types.TOPBAR_MT_file.remove(menu_func)
     
if __name__ == "__main__":
    register() 

not ideal but works

1 Like

Ok! That works! thx…

Updated to current API, it works but the quit dialog is being ignored.

# Add-on information
bl_info = {
    "name": "Reboot",
    "author": "(saidenka) meta-androcto",
    "version": (0, 1),
    "blender": (2, 82, 0),
    "location": "File Menu",
    "description": "Reboot Blender without save",
    "warning": "",
    "wiki_url": "https://blenderartists.org/t/reboot-blender-addon/640465",
    "tracker_url": "",
    "category": "System"
}


import bpy
import os, sys
import subprocess


class BLENDER_OT_Restart(bpy.types.Operator):
    bl_idname = "wm.restart_blender"
    bl_label = "Reboot Blender"
    bl_description = "Blender Restart"
    bl_options = {'REGISTER'}

    def execute(self, context):
        py = os.path.join(os.path.dirname(__file__), "wm.console_toggle.py")
        filepath = bpy.data.filepath
        if (filepath != ""):
            subprocess.Popen([sys.argv[0], filepath, '-P', py])
        else:
            subprocess.Popen([sys.argv[0], '-P', py])
        bpy.ops.wm.quit_blender()

        return {'FINISHED'}


def menu_draw(self, context):
    layout = self.layout
    layout.separator()
    layout.operator("wm.restart_blender", text="Restart", icon='PLUGIN')
    layout.separator()
    prefs = bpy.context.preferences
    view = prefs.view
    layout.prop(view, "use_save_prompt")


def register():
    bpy.utils.register_class(BLENDER_OT_Restart)
    bpy.types.TOPBAR_MT_file.append(menu_draw)


def unregister():
    bpy.utils.unregister_class(BLENDER_OT_Restart)
    bpy.types.TOPBAR_MT_file.remove(menu_draw)


if __name__ == "__main__":
    register()

I’ll be keeping these and other mods in my Github.

3 Likes

Very useful thank you very much :slight_smile:

thanks. I’ll take a look at what you did.