Skip to content

Buttons

DESKTOP-6PITPE2\amade edited this page Nov 14, 2022 · 6 revisions

Adding

There are 3 requirements to creating a button:

  1. The function must have 2 parameters
  2. The function must return operation result, for example return {"FINISHED"}
  3. The function must be decorated with @MakeButton

You can quickly paste a snippet of code with an example button by using the side menu button in the text editor.

Or copy the code below:

@MakeButton("My Tab/My Panel/My Button", "VIEW_3D")
def example_func(self, context):
	#Do stuff here
	return {"FINISHED"}

There are 2 parameters that the MakeButton decorator can take:

  1. Where is the button located:

This is broken down into 3 parts separated by / symbol. First is the name of the tab, second is the name of panel, and third is the label on the button.

  1. Which area the button belongs to:

This defaults to VIEW_3D which is the 3D viewport, check here for more options.

To make a button appear in the NLA editor simply do this:

@MakeButton("My Tab/My Panel/My Button", "NLA_EDITOR")
def example_func(self, context):
	#Do stuff here
	return {"FINISHED"}

If we run the example code now we will end with up this result:

Reloading

Any time the function is modified the code needs to be reloaded. To do this, simply run the script containing the function.

Removing

Currently the only way to remove old buttons is to open the file again or use the Purge buttons button:

Persistance

To ensure the buttons are always created as soon as the file is loaded, every script containing the functions must be registered, to do so you can check the following box: