I am interested in creating a script that would prompt the user to either set up or starting working in a set of project folders when blender starts up. Thanks

more details...

I was hoping to do this as a modal pop-up prompting the user whether they would like to create a new project file. If yes, then present them with a dialog window that would allow them to either accept a set of defaults that they can create/save or alter for specific use in any given project. For instance, a VFX project would likely need a place for media files but would probably not need a folder for a rig(s).

Perhaps this will be a moot point with the work going on in asset management now.

  • 2
    $\begingroup$ Can you give some more details? executing Python code on 'new file' is possible but it seems you want to initiate some kind of interaction with the user (some menu?), and Im not sure if this can work or not without more details. $\endgroup$ – ideasman42 Dec 26 '13 at 22:43
  • $\begingroup$ Like a popup, that let's the user select from a list of templates (startup blends)? Or shall the script create asset blends for every new blend the user create? $\endgroup$ – CodeManX Dec 28 '13 at 13:57

You can capture the event like:

import bpy
from bpy.app.handlers import persistent

def new_file_handler(scene):
    if not bpy.data.filepath:
        print("New file!")


In order to run a popup dialog, a little hack is required to delay the operator invocation (because there's no valid context for a dialog at the time of the load_post callback):

bl_info = {
    "name": "New file prompt",
    "author": "CoDEmanX",
    "version": (1, 0),
    "blender": (2, 69, 0),
    "location": "File > New",
    "description": "Open a popup dialog after a new blend is created",
    "warning": "",
    "wiki_url": "",
    "tracker_url": "",
    "category": "System"}

import bpy
from bpy.app.handlers import persistent

class SimpleOperator(bpy.types.Operator):
    bl_idname = "object.simple_operator"
    bl_label = "Simple Object Operator"
    bl_options = {'REGISTER', 'UNDO'} #?

    prop = bpy.props.StringProperty(name="Material", maxlen=63)
    mats = bpy.props.CollectionProperty(type=bpy.types.PropertyGroup)

    def poll(cls, context):
        return not context.blend_data.filepath

    def execute(self, context):
        return {'FINISHED'}

    def draw(self, context):
        layout = self.layout
        layout.prop_search(self, "prop", self, "mats", icon='MATERIAL')

    def invoke(self, context, event):
        for i in range(1, 7):
            self.mats.add().name = "Material %i" % i
        return context.window_manager.invoke_props_dialog(self)

def scene_update_handler(scene):

def new_file_handler(scene):
    if not bpy.data.filepath:
        print("New file!")

def register():

def unregister():

if __name__ == "__main__":

You may want to remove

bl_options = {'REGISTER', 'UNDO'}

so it doesn't appear in the Redo panel afterwards.

It also shows the dialog on Blender startup (needs to be installed as addon and enabled by default). This may not work with older versions, which did not trigger load events for the startup.blend. Note that the dialog may overlay the splashscreen, but there's no real problem with that.

  • $\begingroup$ Nice code :) Happy me :) $\endgroup$ – matali Mar 12 '14 at 15:03

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.