Quickly accessing a script

Ok, so I have a script. It works well, and it does it’s job very well for something that I find myself doing repeatedly (set the 3D cursor to 0,0,0, set the origin to the 3D cursor, and then set geometry to Origin).

At this point I’ve spent a couple hours looking for add-ons, watching tutorials, etc. trying to figure out how to add the ability to run this script through a simple keystroke.

Is there some built in function for macros or scripts that I’m completely missing here, or is this really as involved and complex as it seems?

Hi man,
i am struggling too for understanding the material but here what i know.

You can write things in the scripting editor, but that will not automatically make an operator.

import bpy
print ("i do something")

there is no way to call this , because is just some code.
You can define an operator to make your actions.
the operator will have a bl_idname that you can call via buttons keyboards …

class TEST_OP_MYACTIONS(bpy.types.Operator):     
    bl_idname = "wm.myactions"
    bl_label = "test actions"
    def execute(self, context):  
        print ("i will do something")

But you have to “register” an operator,
that will say to blender to learn and save that script for the rest of the session (until closed)
Once is registered you can call the operat

def register(): 

def unregister():

if __name__ == "__main__":

Once this is done without errors you can call the operator
but there is a different way for every place.
the only constant is the bl_idname you give to him

Here an example using the template simple operator,
beware that this operator name start with “object.”
this will make the operator run only if you are in object mode
for make it run in every case i name it " wm. "

Its a bit tricky but you can find the panel in preference, keymap
i am using the 290, so may be different, you add a shortcut under the right section “object” or “window” for wm… and type in the blidname. i set this to 0

I forgot, to say that this will give you a script that you have to run every time you load blender,
Because blender will remember the shortcut to the operato but not the operator.
For make blender reload the script too, you have to make it become an addon !

I just have like 6 script open in my blender , and since i am working on and tweaking all , its just more easy hit Run every time i need it.

1 Like

Thank you. Am at work currently, but will apply this when I get home this evening. I appreciate the information. :slight_smile: