UIカスタマイズ

Blender2.5になってインタフェースがPythonで定義されるようになった。
定義するのはボタンの並び順とかレイアウト関連のもので、
.blender\scripts\ui
ディレクトリに配置されている。


ファイル名がspace_XXXというのは、エリアが表示している内容(outliner、propertiesや3D Viewなど)に応じてメニューを構成したりする。
space_outliner.pyだとヘッダについているメニュー(View、Search)などが書いてある。


ファイル名がproperties_XXXというのは、エリアがpropertiesを表示している時の中身の方のレイアウトを定義している。
properties_object.pyだとtransform, transform_locks, relationsが順に書いてある。

PropertiesのObjectにパネルを追加してみる

Outlinerの親子関係で子孫を全部表示・非表示にするボタンを追加してみる。

下記を.blender\scripts\uiにz_myprops.pyとかのファイル名で配置する。
パネルの表示順がbpy.types.registerの呼ばれた順ぽいので、一番最後に呼ばれるようにファイル名の頭にzをつけといた。

import bpy

narrowui = 180

###############################################################################
# operator
###############################################################################
def do_hierarchycal(action, current):
    if not current:
        return
    action(current)
    for child in current.children:
        do_hierarchycal(action, child)


class ShowHierarchycal(bpy.types.Operator):
    '''Show object hierarchycal'''
    bl_idname = "object.show_hierarchy"
    bl_label = "Show Hierarchy"
    bl_options = {'REGISTER', 'UNDO'}

    def poll(self, context):
        return context.object

    def execute(self, context):
        def action(o):
            o.restrict_view=True
        do_hierarchycal(action, context.object)
        return {'FINISHED'}


class HideHierarchycal(bpy.types.Operator):
    '''Hide object hierarchycal'''
    bl_idname = "object.hide_hierarchy"
    bl_label = "Hide hierarchy"
    bl_options = {'REGISTER', 'UNDO'}

    def poll(self, context):
        return context.object

    def execute(self, context):
        def action(o):
            o.restrict_view=True
        do_hierarchycal(action, context.object)
        return {'FINISHED'}

operators=[
    ShowHierarchycal,
    HideHierarchycal,
    ]


###############################################################################
# panel
###############################################################################
class ObjectButtonsPanel(bpy.types.Panel):
    bl_space_type = 'PROPERTIES'
    bl_region_type = 'WINDOW'
    bl_context = "object"


class OBJECT_PT_outline(ObjectButtonsPanel):
    bl_label = "Outline"
    bl_default_closed = True

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

        ob = context.object
        wide_ui = context.region.width > narrowui

        split = layout.split()

        col = split.column()

        row = col.row()
        row.prop(ob, "restrict_view", text="Visible")

        row = col.row()
        row.operator("object.show_hierarchy", 
                text="Show objects hierarchycal")

        row = col.row()
        row.operator("object.hide_hierarchy", 
                text="Hide objects hierarchycal")


###############################################################################
# register
###############################################################################
classes = [
    OBJECT_PT_outline,
]

def register():
    register = bpy.types.register
    for op in operators:
        register(op)
    for cls in classes:
        register(cls)

def unregister():
    unregister = bpy.types.unregister
    for cls in classes:
        unregister(cls)
    for op in operators:
        unregister(op)

if __name__ == "__main__":
    register()

▼Custom Propertiesの次にOutlineパネルが追加された

参考
http://www.blender.org/development/release-logs/blender-250/updated-gui/