Need help with addon.

I am trying to make an addon that when clicking on a button in the toolbar saying “19” it will run this script and if possible have it switch to layer 0 when hitting a hotkey or key.

import bpy

#have this script run when clicking on a button in the toolbar
l = [False] * 20
l[19] = True
bpy.context.scene.layers = l




#then have this run afterward when pressing a key or hotkey


l = [False] * 20
l[0] = True
bpy.context.scene.layers = l



Thanks.

hi, sorry I don’t understand what do you want :frowning:

Make this script run when clicking on a button in the toolbar ( t key)

l = [False] * 20
l[19] = True
bpy.context.scene.layers = l

I think the easy and fast way is to do some add on

may be you should try with blender templates… here fast code for your code:

bl_info = {    "name": "Execute Script",
    "author": "dIEGO QUEVEDO",
    "version": (1, 0),
    "blender": (2,7,1),
     "location": "View3D > EditMode > ToolShelf",  
    "description": "execute script",
    "warning": "",
    "wiki_url": "",
    "category": "Mesh"}




import bpy






def script(self):
    l = [False] * 20
    l[19] = True
    bpy.context.scene.layers = l
    




class executescriptoperator(bpy.types.Operator):
    """execute script """
    bl_idname = "mesh.executescript"
    bl_label = "Execute Script"
    bl_options = {'REGISTER', 'UNDO'}


    @classmethod
    def poll(self, context):
        obj = context.active_object
        return all([obj is not None, obj.type == 'MESH', obj.mode == 'EDIT'])


    def execute(self, context):
        script(self)
        return {'FINISHED'}
		
class executescriptPanel(bpy.types.Panel):
    bl_space_type = "VIEW_3D"
    bl_region_type = "TOOLS"
    #bl_context = "editmode"
    bl_label = "execute script"
   
    @classmethod
    def poll(cls, context):
        return (context.mode == 'EDIT_MESH')
    
    def draw(self, context):
        layout = self.layout
        row = layout.row(align=True)
        row.operator(executescriptoperator.bl_idname) 
		




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


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




if __name__ == "__main__":
    register()



and the result:


Thank you so much! you must be real good with coding.
Now what exactly do I do to add a second button under it that executes the same script but different layer. The first one takes you to layer 19, I’d like to have the second button take you back to layer 1.

hi, you don’t need a second button… the only think that you need is some if, else condition in order to check if actual layer ir 19 or 1… and do something in each case… also you can use the “case” condition…

I thought duplicating the script and changing the layer number would make another button under it.

if you want to change the current frame, your actual script code is strange… change that for this:

def script(self):    
    current_frame = bpy.data.scenes[0].frame_current
    if current_frame != 19:
        bpy.context.scene.frame_current = 19
       
    else:
        bpy.context.scene.frame_current = 1

this work with the same button

best