Is it possible to simulate the Shift+LMB
for hiding a parent object with its children as in the outliner. Now based on this and this I am iterating over the children objects and hide_set(True) them individually:
def toggle_hide (list, mode=True):
children_list = []
for obj in list:
if obj.children:
children_list.append(obj.children)
obj.hide_set(mode)
if children_list:
for child in children_list:
toggle_hide (child)
bpy.data.objects["parent"].hide_set(True)
toggle_hide(bpy.data.objects["parent"].children)
bpy.data.objects["parent"].hide_set(True)
hides only the parent object leaving the children unhidden, which I need to do it afterwards recursively.
My guess is that under the hood might be the same procedure that is happening but I was wondering if someone can just call the corresponding outliner build in function instead of re-implementing it or by passing some flag to the hide_set()
though as I see it takes only a view_layer
id.
Update (not working):
Now I want to add the solution from @batFINGER to a class, e.g.
import bpy
from bpy.props import BoolProperty
class Utility:
class AddHidingProperty:
def __init__(self):
bpy.types.Object.hide_children = BoolProperty(update=self.hide_children)
bpy.types.TEXT_HT_footer.append(self.draw)
def hide_children(self, obj, context):
obj.hide_set(obj.hide_children)
for o in obj.children:
o.hide_children = obj.hide_children
# function to draw the checkbox in the editor footer
def draw(self, obj, context):
layout = obj.layout
ob = context.object
layout.prop(ob, "hide_children")
However when I call the Utility.AddHidingProperty()
, this gives me the following error: ValueError: bpy_struct "Object" registration error: hide_children could not register
.
Update 2 (working):
The following seems to work but I am not sure whether it is a good approach:
class Utility:
class AddHidingProperty:
def __init__(self):
def hide_children(obj, context):
obj.hide_set(obj.hide_children)
for o in obj.children:
o.hide_children = obj.hide_children
# function to draw the checkbox in the editor footer
def draw(obj, context):
layout = obj.layout
ob = context.object
layout.prop(ob, "hide_children")
bpy.types.Object.hide_children = BoolProperty(update=hide_children)
bpy.types.TEXT_HT_footer.append(draw)