9
$\begingroup$

I want to use Blender for a specific task where the user (not me) is just presented with a limited set of tools and nothing else.

Using the usual possibilities configuring the GUI lead my quite close to my target.

Beside that I want the toolbar only contain my tools/buttons. Editing space_view3d_toolbar.py gave me an empty toolbar which I then populate with my own tools.

However I would like to NOT alter Blenders core files and just use a script registered in my startup.blend which does the cleaning.


So my question is:

How to iterate through the existing Panels (for all modes) on the toolbar and remove them?

$\endgroup$
  • 1
    $\begingroup$ Please ask Q2 as a separate question $\endgroup$ – ideasman42 Nov 26 '14 at 14:29
10
$\begingroup$

To remove panels, you can simply unregister the classes.

Here we remove all View 3D Panels:

import bpy
for pt in bpy.types.Panel.__subclasses__():
    if pt.bl_space_type == 'VIEW_3D':
        bpy.utils.unregister_class(pt)

Of course you may want to do some other checks to only remove some of the panels... try use the Python console to inspect the panel types and see which members are useful to check (__name__ for example)

Note that __subclasses__ is a standard Python method.

This works for other areas too, operators, menu's, (any class which can be registered).


To run Multiple times you need to check if the class has a specific RNA attribute:

import bpy
for pt in bpy.types.Panel.__subclasses__():
    if pt.bl_space_type == 'VIEW_3D':
        if "bl_rna" in pt.__dict__:   # <-- check if we already removed!
            bpy.utils.unregister_class(pt)

Note that this making use of an internal attribute and is not a documented part of the Python API, its used for Blender's own tracking of classes.

$\endgroup$
  • $\begingroup$ It works the first time. Also in my registered script but then I get this error: read blend: G:\GUI10.blend ... <class 'Toolbar.VIEW3D_PT_LayoutDemoPanel'> Traceback (most recent call last): File "G:\GUI10.blend\Toolbar.py", line 156, in <module> File "G:\GUI10.blend\Toolbar.py", line 143, in register RuntimeError: unregister_class(...):, missing bl_rna attribute from 'RNAMeta' instance (may not be registered) $\endgroup$ – Carsten Wartmann Nov 26 '14 at 16:20
  • $\begingroup$ these comments are quite short, am I supposed to edit my original Q when I have to say more? $\endgroup$ – Carsten Wartmann Nov 26 '14 at 16:23
  • $\begingroup$ It seems that it only works on a "clean" file (blender just started). After unregister a class they are still in the namespace(?) and it fails. Still struggeling with my script, even after a fresh Blender start only SOME classes are unregistered before the error. $\endgroup$ – Carsten Wartmann Nov 26 '14 at 16:36
  • $\begingroup$ me again: catching the error now with a try: Not sure if this is a good idea... $\endgroup$ – Carsten Wartmann Nov 26 '14 at 17:04
  • $\begingroup$ @CarstenWartmann - updated the answer so you can re-run without exceptions. $\endgroup$ – ideasman42 Nov 26 '14 at 18:38

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.