0
$\begingroup$

I created an addon that ads my own panel in 3dView Properties, it consist of selected settings from View, Display and Shading panels. Now I want to disable those panels. I could comment them out or add poll check in space_view3d.py file but I don't want to modify interface files permanently. Is there a way to disable panels from another python script?

$\endgroup$
1
$\begingroup$

Import and unregister the UI panel

Simple test script, toggles the rego of the 3DView Properties View Panel, by looking at its is_registered property.

import bpy
# import the view panel
from bl_ui.space_view3d import VIEW3D_PT_view3d_properties as VP
# toggle rego
if VP.is_registered:
    bpy.utils.unregister_class(VP)
else:
    bpy.utils.register_class(VP)

Would suggest this is done in your register / unregister methods.

IMO this is a slippery slope, if you are going to distribute your addon, as other addons may append prepend to those panels.

$\endgroup$
0
$\begingroup$

Panels get displayed when their class is registered. This hapens in the \scripts\startup\bl_ui\__init__.py file:

def register():
    from bpy.utils import register_class
    for mod in _modules_loaded:
        for cls in mod.classes:
            register_class(cls)

You can unregister those classes when your addon is registered and register them back when your addon gets unregistered, but it's important it gets executed after the __init__.py code, not before it. That is usually the case, as addons are loaded after UI, but you can check with a Blender developer to be sure. This is something to be careful about.

You can also modify the space_view3d.py itself. You can do this from your addon with python too, granted you have the permission to write to the files. This can be more problematic if the user deletes the addon files and its unregister function gets never called to restore the file back. Also the write permission might be a problem.

$\endgroup$

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.