Summer sale on BlenderMarket starting 8/3 - get 25% off my add-ons

BLENDERNOMY

Initialize Stored Views Automatically

Improving the Stored Views Addon

The Stored Views add-on that comes with Blender by default is incredible. One potential downside is that you have to Initialize it each time you create a new file. I find this annoying. Fortunately, it's super easy to script up a solution!

Set up Your Script

Set up the text editor

If you haven't done it before, it's extremely simple to set up a script in Blender. First, open up a Text Editor workspace, make a New Text Object, and turn on Register from the Edit Menu:

Figure 1.1
Make sure to turn on Register and create a New Text Object

Turning on Register means that the Text Editor will recognize whatever you put in here as a Python script. You could turn on Live Edit as well, which will automatically run your script, but this will run your script anytime the text changes. We just want to run the script once- when a new file is created- so leave that off.

Set a template for the script

Now, we need the script itself. Blender comes with a bunch of scripting templates that make it super simple to write scripts. In this case, the Simple Operator script will do the trick. You can find that under:

Templates > Python > Operator Simple

Get the function to Initialize

Blender also makes it simple to get the Python command for any action- just right click and choose "Copy Python Command". If you go to the Stored Views Panel in the Properties sidebar, you'll be able to right-click on "Initialize" and copy the Python command for this button. No worries if you've already initialized, the command is this:

bpy.ops.view3d.stored_views_initialize()

If you haven't yet, go ahead and choose the Simple Operator template. You'll see a bunch of text get added to the editor.

WHY USE AN OPERATOR?

Are you wondering why we can't just use that one line- bpy.ops.view3d.stored_views_initialize()? You can try, if you want- you'll get an error. Specifically, you'll get a context error, where Blender doesn't know how and when to use that command. There are a few ways around this error, but using the Simple Operator template is by far the easiest. It also works every time, which is a nice perk.

Initialize Stored Views Automatically

MAKE THE SCRIPT FUNCTIONAL

Right at the top, starting at line 3, you'll see a main() function. This contains everything the operator does. Don't worry too much if you don't know what that means, all you need to do is replace that code block with this:


        def main(context):
            bpy.ops.view3d.stored_views_initialize()
            bpy.ops.text.run_script()
        

Notice that this script is running itself (on the second line). We're doing this because we don't want to turn Live Edit on.

That's it- at least for the scripting part, anyway.

SET YOUR BLENDER STARTUP FILE

TO recap- we have a script that is Registered, so it can run, and it will run itself automatically. To make this apply to all new files, you need to save this file as your Blender startup file. Make sure that Register is checked on before you save this as the startup file! Here's where you can do that:

File > Defaults > Save Startup File

I personally like to switch the Text Editor to a different view before saving. This way, the script will run automatically in the background, and the Text Editor won't be in your way.

Now, when you open a new file, the Stored Views will initialize automatically.

ShotDial- Switch Camera Views with Just OneKeypress

ShotDial allows you to switch between camera views quickly and easily with just one keypress.

CHECK IT OUT

Site Information

Welcome to Blendernomy! You can find tutorials, addons, downloads, and other content for Blender 3D here.

This site also has web development, web design, Python, JavaScript, and other content- really, whatever I want to write about :)

This site is a personal project. It's not backed by any commercial entity, nor is it sponsored by or affiliated with the Blender Foundation.