Reputation: 61
I found this tutorial and have been following along trying to create my own Panel in the Toolshelf but mine won't work, for no obvious reason.
I'm using Blender 2.63, and I have also tried the exact same script in Blender 2.58 and 2.56, both having the exact same result. NOTHING.
I've been through the script more times than I can count and I haven't seen any typos or incorrect words, yet it still does nothing. What's worse is I don't get any error messages.
When I click on the 'Run Script' button in the text editor, the only message I get is that I have run the script. In the tool shelf it displays it at the bottom in the same way as it would if you were to add a cube, only with the cube you are given some options such as the location/scale etc, of the cube. It is also displayed 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, as Blender is giving me no idea at all if something is wrong.
Upvotes: 5
Views: 3741
Reputation: 251428
You defined a class, but you never instantiated it. If you want your script to do anything, you need to do something with that class. However, it's not clear what that would be. It doesn't look like your class really does anything; it seems to be some sort of "panel" that would be added to a larger interface.
You should look into the documentation to find examples of what you're trying to do. Presumably you will need to create more than just a single panel.
Upvotes: 0
Reputation: 298364
I haven't worked with 2.5/2.6's new API yet (sadly), but the documentation is never a bad place to look: http://www.blender.org/documentation/blender_python_api_2_57_release/bpy.types.Panel.html
The example code:
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)
Have you tried adding this line to the end?
bpy.utils.register_class(customToolshelfPanel)
Creating the class is one thing, but you need to register it with the UI as well.
Upvotes: 1
Reputation: 2672
you need to register the class.. add this to the bottom of the script
bpy.utils.register_class(customToolshelfPanel)
and to ensure that the script gets removed after blender has been closed you need to also unregister it
bpy.utils.unregister_class(customToolshelfPanel)
you might also want to press T a few times to update the interface after running the script.
Upvotes: 3