2
$\begingroup$

Update:

Let me ask a slightly different way, since I may be over-complicating things.

If working from the UI there's an option to do this:

enter image description here

You can Shift-Click to hide parent and children objects. How do you accomplish this programmatically? The only way I've found so far just hides the main object:

row.prop(wall, "hide_viewport")

Original Question

I'm working on an addon that's essentially a kitchen designer, so the base objects that need tracking are walls. Each wall has objects snap to it and become the parent object for everything underneath.

The walls need the ability to be hidden, along with all of the associated child objects. This requires a function for a little processing. If all of the walls could be defined ahead of time, I know how to accomplish this (create the class functions and register them, etc).

However walls are added as needed, with a simple loop that tracks and displays them:

    row.label(text="Walls")

    if object.expanded_walls:
        row = box.row()
        for wall in objs:
            row = box.row()
            row.prop(wall, "name")
        --> row.##boolean_flag(script_that_hides, arg_with_wall_id)

This list is updated dynamically in the display, so displaying any wall property is easy.

But, I can't figure out how to put a simple boolean flag with each line item capable of calling a function data from objects in the same row. Any way to do that?

$\endgroup$
1
$\begingroup$

Boolean with update

enter image description here

  • A hide_children boolean property is added to all objects.
  • If the property is updated all children are hidden, plus their hide_children is set, propagating the hide down the hierarchy.

2.8x Test script, with property drawn on text editor footer.

import bpy
from bpy.props import BoolProperty


def hide_children(self, context):
    self.hide_set(self.hide_children)
    for o in self.children:
        o.hide_children = self.hide_children


bpy.types.Object.hide_children = BoolProperty(update=hide_children)


def draw(self, context):
    layout = self.layout
    ob = context.object
    layout.prop(ob, "hide_children")


bpy.types.TEXT_HT_footer.append(draw)

Similarly to only toggle children

def hide_children(self, context):
    for o in self.children:
        o.hide_set(self.hide_children)
        o.hide_children = self.hide_children

These are object properties, to layout for all objects in scene

for o in scene.objects:
    layout.prop(o, "hide_children")

Note: For 2.8x would be very tempted to do this with collections, and their hierarchy instead of objects.

$\endgroup$
  • $\begingroup$ Is it possible to pass this function an object that isn't currently the active object? For instance: "row.operator('view3d.hide_children', text= "Text") sits inside a panel as a button. When pressed I would like to send it the object info contained in that row, but it doesn't appear these can take other params. Either way, looks like you are correct about reorganizing according to Collections... Seems to be much easier to control if everything is laid out that way instead. $\endgroup$ – Sam Vimes Aug 2 at 16:55
  • $\begingroup$ See latest edit. $\endgroup$ – batFINGER Aug 3 at 7:45

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.