Blender script to create toolbar gives no results

I found this tutorial and watched the attempt to create my own toolbar in Toolshelf, but mine will not work, because there is no obvious reason.

I am using Blender 2.63, and I also tried the exact same script in Blender 2.58 and 2.56, both have the same result. NOTHING.

I went through the script more times than I can count, and I did not see any typos or incorrect words, but it still does not do anything. To make matters worse, I am not getting any error messages.

When I click on the Run Script button in a text editor, the only message I get is that I ran the script. On the shelf of the tool, it displays it at the bottom just as if you were adding a cube, only with the cube you were given some parameters, such as location / scale, etc. Cuba. It also appears in the info window as:

bpy.ops.text.run_script() 

This is what my code looks like:

 import bpy class customToolshelfPanel(bpy.types.Panel): bl_space_type = "VIEW_3D" bl_region_type = "TOOLS" bl_context = "objectmode" bl_label = "Custom Toolshelf Panel" def draw(self, context): layout = self.layout col = layout.column(align=True) col.label(text="Add:") col.operator("mesh.primitive_plane_add", icon="MESH_PLANE") col.operator("mesh.primitive_cube_add", icon="MESH_CUBE") 

Any help at all would be appreciated since Blender does not give me any ideas at all if something is wrong.

+4
source share
3 answers

you need to register the class .. add this to the end of the script

 bpy.utils.register_class(customToolshelfPanel) 

and to make sure that the script is deleted after closing the blender, you also need to unregister it

 bpy.utils.unregister_class(customToolshelfPanel) 

you can also press T several times to update the interface after running the script.

+2
source

I haven't worked with API 2.5 / 2.6 yet (unfortunately), but the documentation is never bad: http://www.blender.org/documentation/blender_python_api_2_57_release/bpy.types.Panel.html

Code example:

 import bpy class HelloWorldPanel(bpy.types.Panel): bl_idname = "OBJECT_PT_hello_world" bl_label = "Hello World" bl_space_type = 'PROPERTIES' bl_region_type = 'WINDOW' bl_context = "object" def draw(self, context): self.layout.label(text="Hello World") bpy.utils.register_class(HelloWorldPanel) 

Did you try to add this line to the end?

 bpy.utils.register_class(customToolshelfPanel) 

Creating a class is one thing, but you also need to register it using the interface.

0
source

You defined a class, but you did not create it. If you want your script to do something, you need to do something with this class. However, it is not clear what it will be. This is not like your class is really doing something; it seems to be some kind of β€œpanel” to be added to the larger interface.

You should study the documentation to find examples of what you are trying to do. Presumably you will need to create more than just one panel.

0
source

All Articles