I’m a beginner at scripting python and was wondering how to run a script by pressing a button in the tools tab. I’d also like to have another script run when a key is pressed. I already have the scripts but what exactly can you add above it that will make the script run afterwards?
and addon is the thing that you want… and may be with some modal parameters
Can you show me how that looks?
Like the setup?
It’s mostly covered here:
Here’s the additional class to add the operator created in the tutorial as a button in a new panel of the 3D View’s sidebar, Tools tab:
class HelloWorldPanel(bpy.types.Panel): """Creates a Panel in the Object properties window""" bl_label = "Hello World Panel" bl_idname = "OBJECT_PT_hello" bl_space_type = 'VIEW_3D' bl_region_type = 'TOOLS' bl_category = "Tools" def draw(self, context): layout = self.layout layout.operator("object.cursor_array")
Note that this class needs to be registered.
If you want to make your bpy life easier, replace all calls to
bpy.utils.register_class(…) and bpy.utils.unregister_class(…)
by one call to bpy.utils.register_module(name) and bpy.utils.unregister_module(name)