0
$\begingroup$

First, I want to make sure I'm using the right terms and talking about the proper part of the Blender workspace. From reading a few different answers on SE:Blender, and a few other sources, my understanding is that the area in the blue box below is often called the "Properties area," and that the area in the red box is the "Properties Editor." But I've also read things that make me think the area in the blue box is not called a "Properties area," or anything like that.

enter image description here

So, first, can someone provide me the correct names for these areas? And, since I'm not sure of names, I'll just call them the highly technical terms of "Red Area," and "Blue Area."

A user on SE:Blender sent me an example script that created a tab and panel in the red area, so there was another panel for a specific use. I tried it a couple months ago and it worked. I've been heavily involved elsewhere for awhile and came back to this issue about 2-3 weeks ago. I copied his script in and it didn't work - no panel in the Red Area.

So I went into the Script Editor and picked the "Ui Panel" from the templates and ran that. It looked to me like it was supposed to add a panel to the Red Area, but it didn't. I checked the tabs in the 3D View and nothing was added there at all.

Then I copied the script in the image above from this answer to test it:

import bpy
from bpy.props import FloatVectorProperty, BoolProperty

class CarPanel(bpy.types.Panel):
    """Creates a Panel in the Object properties window"""
    bl_label = "Car Details"
    bl_idname = "OBJECT_PT_hello"
    bl_space_type = 'PROPERTIES'
    bl_region_type = 'WINDOW'
    bl_context = "object"

    @classmethod
    def poll(cls, context):
        return context.object.get("Capot", False)

    def draw(self, context):
        layout = self.layout

        car = context.object
        layout.prop(car, '["Capot"]')
        #bools don't show well (1 or 0 integer)
        layout.prop(car, "switch")
        layout.prop(car, '["bool"]')
        col = layout.column()
        col.prop(car, '["prop"]')
        # car color property
        row = layout.row()
        row.prop(car, "car_color")
        # object color rgba
        row = layout.row()
        row.prop(car, "color")

def register():
    # define a registered property (available for all Object types size=4 gives rgba)
    bpy.types.Object.car_color = FloatVectorProperty(subtype='COLOR', size=3)
    bpy.types.Object.switch = BoolProperty()
    bpy.utils.register_class(CarPanel)

def unregister():
    bpy.utils.unregister_class(CarPanel)

if __name__ == "__main__":
    register()

I did not see a panel added in the Red Area or anywhere else at all.

Last example - I went to Blender documentation and this page has this script:

import bpy


class ObjectSelectPanel(bpy.types.Panel):
    bl_idname = "OBJECT_PT_select"
    bl_label = "Select"
    bl_space_type = 'PROPERTIES'
    bl_region_type = 'WINDOW'
    bl_context = "object"
    bl_options = {'DEFAULT_CLOSED'}

    @classmethod
    def poll(cls, context):
        return (context.object is not None)

    def draw_header(self, context):
        layout = self.layout
        layout.label(text="My Select Panel")

    def draw(self, context):
        layout = self.layout

        box = layout.box()
        box.label(text="Selection Tools")
        box.operator("object.select_all").action = 'TOGGLE'
        row = box.row()
        row.operator("object.select_all").action = 'INVERT'
        row.operator("object.select_random")


bpy.utils.register_class(ObjectSelectPanel)

I ran it and it seems to have no effect at all.

So what am I doing wrong? Why don't these scripts seem to do anything and what do I need to do to add a panel to the Red Area? (And what are the proper names for the Red Area and Blue Area?)

$\endgroup$
5
  • 1
    $\begingroup$ If you mean adding a panel on the left of the red area, you can't with Python. You'll have to dive into the source code for that. If you open the object properties (Orange square icon) you'll see your panel there in addition to all the default ones $\endgroup$ – Gorgious Mar 7 at 11:37
  • $\begingroup$ For the record: Blue is the Outliner, Red is the so called Properties area which is always context dependent, meaning dependent on what you have selected in the Outliner or the 3d viewport. $\endgroup$ – brockmann Mar 7 at 16:32
  • $\begingroup$ @brockmann: Thank you for clarifying that for me. I've gone through multiple books and tutorials, but it's a lot of information to absorb. I do better remembering the logic and what does what, but names are easily confused. $\endgroup$ – Tango Mar 7 at 16:55
  • $\begingroup$ Easy, I'd suggest start here: blender.stackexchange.com/questions/57306/… $\endgroup$ – brockmann Mar 7 at 16:57
  • $\begingroup$ @brockmann Again, thank you! $\endgroup$ – Tango Mar 7 at 17:22
2
$\begingroup$

Texture context

when adding a panel to the properties area we set the context as signified by the icon on LHS. This is set with bl_context. To get a panel in the questions "Red Area"

bl_context = "texture"

all the examples given in question are in object context. Press the Object tab. (cube)

How to enable or disable panels with the click of a button

Eg for Hello World example.

import bpy


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 = 'PROPERTIES'
    bl_region_type = 'WINDOW'
    bl_context = "texture"

    def draw(self, context):
        layout = self.layout

        obj = context.active_object

        row = layout.row()
        row.label(text="Hello world!", icon='WORLD_DATA')

        row = layout.row()
        row.label(text="Active object is: " + obj.name)
        row = layout.row()
        row.prop(obj, "name")

        row = layout.row()
        row.operator("mesh.primitive_cube_add")


def register():
    bpy.utils.register_class(HelloWorldPanel)


def unregister():
    bpy.utils.unregister_class(HelloWorldPanel)


if __name__ == "__main__":
    register()
$\endgroup$
1
  • $\begingroup$ A couple points to clarify. The 1st comment on my question states I can't add a new tab and, since you're talking about context, I take it that's correct - you can't add a complete panel? Also, by context, if I switch from texture to object, then this new panel should show up in the object context, right? And will it always show up in the Object tab? $\endgroup$ – Tango Mar 7 at 16:59

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.