Does this addon exist? ("layer toggle check")

I use the 4th layer in blender for my lighting and camera(s). I shift+4 before I press f12 to render … and I forget a lot. Even if I don’t forget, it becomes tedious since I have about 3-4 other layers I do this with too.

What I want is for blender to check whether or not X layers are enabled when a hotkey is pressed (f12 in this case), and if not, to toggle them on before rendering.

Does something like this exist? I couldn’t find anything via google. And if not, is something like this difficult to create?

This isn’t hard to create, you just need to add a pre-render handler to toggle those layers on: http://www.blender.org/api/blender_python_api_2_76_2/bpy.app.handlers.html?highlight=handler#bpy.app.handlers.render_pre

By the way, that signature is awesome.

Thank you for the link … though do you have other links you could share that would send me down the right path? Specifically for how to check if layers are enabled. Because sometimes I have the layers already enabled when I render, and I wouldn’t want it to disable them instead. All I could find was this.

I have zero knowledge of python, though I have created one basic addon in the past (making a hotkey for changing the IK solver) by googling random things and trial and error… lmao. So I’m willing to try here, I’m not asking for anyone to do the work for me. I just don’t know the keywords to search to find what I need.

Shameless bump … !

You can see if the fourth layer is visible with:
bpy.context.scene.layers[3]

It will be True if visible and False if not visible in the scene. (try print(bpy.context.scene.layers[3]) in the python console)
To set the layer to be visible you can simply do bpy.context.scene.layers[3] = True.

For the handler thingy you can read this: http://blender.stackexchange.com/questions/44334/how-to-write-a-bpy-app-handlers-handler-thats-only-called-once

Thanks! That’s exactly what I needed. I completely forgot about looking in the info’s console to get the names… :o

This works fine for me but I’m curious if this is properly done…? I decided to create a separate hotkey instead of creating a handler.

bl_info = {    "name": "Render Specific Layers",
    "category": "Screen",
}


import bpy


def main(context):
    bpy.context.scene.layers[0] = True
    bpy.context.scene.layers[3] = True
    bpy.context.scene.layers[5] = True
    bpy.context.scene.layers[6] = True
    bpy.ops.render.render('INVOKE_DEFAULT')
        
class SimpleOperator(bpy.types.Operator):
    """Tooltip"""
    bl_idname = "render.specificlayers"
    bl_label = "Render Specific Layers"


    def execute(self, context):
        main(context)
        return {'FINISHED'}
        
def register():
    bpy.utils.register_class(SimpleOperator)


def unregister():
    bpy.utils.unregister_class(SimpleOperator)
    
    #call
    bpy.ops.render.specificlayers()

And I’m also wondering… is there a way to specify the layers rather than editing the script each time I want to change them? I’ve seen how to do the toolbar part from this tutorial but I have no idea how to translate that to my script.

I want to do this (below), so you can select them but not change the active layers in the viewport … (this is photoshopped)
http://i.imgbox.com/0FrKOpPw.png

import bpy

class AlwaysRenderPanel(bpy.types.Panel):
    bl_label = "Always Render"
    bl_idname = "RENDER_PT_alwaysrender"
    bl_space_type = 'PROPERTIES'
    bl_region_type = 'WINDOW'
    bl_context = "render"

    def draw(self, context):
        layout = self.layout                     
        
def register():
    bpy.utils.register_class(AlwaysRenderPanel)

def unregister():
    bpy.utils.unregister_class(AlwaysRenderPanel)


if __name__ == "__main__":
    register()