Remove or hide panels from add on.

Hi all…

I’m working on an add-on that manages a custom work flow. I would like to be able to hide panels in the properties window that are not relevant to that workflow. I thought this would be fairly straight forward but I can find nothing that addresses it. Maybe I’m going about this the wrong way.

Ideas?

Thanks.

try this:


import bpy, bpy_types
bpy.utils.unregister_class(bpy_types.bpy_types.SCENE_PT_physics)

for example to remove the gravity panel

By the way, such things can be discovered by using the console auto-complete CTRL+SPACE.

so, in the console (which you can show with [ctrl]+[F4]),
you first need to

import bpy_types

then
type bpy_types.bpy_types. and then ctrl+space to see a humongous list.

Thank you!

That’s just what I was looking for.

upon further inquiry, I see that importing bpy_types is unnecessary – bpy.types seems to work as well.

In my recent scripts I just have a special case for the panel that displays a simple message. Like “This panel is not relevant for this object”. Or display nothing in the draw routine.

I think registering and unregistering class on-the-fly would certainly stress-test the API and the event system.

Can you do this with ‘built-in’ panels? Can you override the draw routine for another panel from an add on?

I have to admit it does feel odd to unregister another class. I would much prefer to simply ‘hide’ panels that I know are not needed. But if it works…

This replaces the draw method of the transform panel of the object props.


import bpy
def goofer(self,context):
    self.layout.label("NA")
bpy.types.OBJECT_PT_context_object.draw = goofer

can also remove the draw method this way


bpy.types.OBJECT_PT_transform.remove(bpy.types.OBJECT_PT_transform.draw)

In playing with this today, the unregister_class method gives the results I’m looking for. The panels I don’t want are completely hidden. I unregister a list of classes in my register method and register them again in my unregister method. So far this seems to be working.

Thanks for the help.

Hi everybody! This is what I was looking for as well, but I cannot seem to find the bpy_types for the Graph Editor to remove it’s menus… can anybody help?

Ps. It would be even better if it was possible to add a poll function to the panels in order to make it appear only in certain cases… Could anybody help me setting it up?

My target is to hide selected panels from the graph editor when the screen name is “Data Anaysis” … !

I might be wrong but I don’t think it’s actually necessary to import bpy_types… I used to and I don’t remember why. I just import the class through the bpy module directly.

from the (shift-f4) console you can type bpy.types. and then ctrl-space to see the list of types. bpy.types.GR completes to a few graph editor things and there is a GRAPH_MT_editor_menus. Is that what you wanted to hack on?

step one:

get a reference to the class you want to alter

from bpy.types import GRAPH_MT_editor_menus

now we need to unregister it

bpy.utils.unregister_class(GRAPH_MT_editor_menus)

next make a poll func

def mypoll(cls,context):
    return context.screen.name == "Data Analysis" # check for typo

put it on the class:

GRAPH_MT_editor_menus.poll = classmethod(mypoll)

and then of course register again

bpy.utils.register_class(GRAPH_MT_editor_menus)

that may or may not work … I didn’t test so good luck

Thank you very much dustractor for your kind answer.

No, although very interesting and probably something I will need in the future, unfortunately it isn’t what I was looking for… something similato to what you wrote (see below) would remove the menus in the header, while what I wanted to remove is the element in the panels you activate with the ‘N’ key. These should be some ‘GRAPH_PT_***’ clas_s (at least PT is what is used in other area types) but they don’t seem to exist for the graph editor…

I tried with ‘GRAPH_MT_editor_menus’ anyway but unregistering it seems to have no effect.

Trying with ‘GRAPH_MT_view’ partly works as it is possible to unregister it (View menu disappears) but not to bind it to a poll call.

In order to be sure the idea was right, I tested it with VIEW3D_PT_view3d_cursor and it perfectly works.

Code below here.

import bpy

from bpy.types import VIEW3D_PT_view3d_cursor

bpy.utils.unregister_class(VIEW3D_PT_view3d_cursor)

def mypoll(cls,context):
    return context.screen.name == "Data Analysis"

VIEW3D_PT_view3d_cursor.poll = classmethod(mypoll)

bpy.utils.register_class(VIEW3D_PT_view3d_cursor)

By the way this replies what I wrote in another post, so thank you very much! :slight_smile:

Sweet! Awesome to hear it works.

Messing with blender ui is about the only kind of programming I would call as one of my specialty. I haven’t in a long time though… currently messing around learning kotlin and yuck java