3
$\begingroup$

For example, there is cube that have boolean modifier with sphere object and sphere object also have union boolean with torus, and the cube also mirrored with empty object as origin.

enter image description here

The question is, how do I select the whole related object on the cube quickly? Is there anyway to do it automatically? A script or add-on is fine.

Addtional info: If you only select the cube then copy it by pressing ⌃ Ctrl + C the whole related objects will also copied.

Then, if you paste ⌃ Ctrl + V the whole objects will automatically be selected, this selection method is what I meant.

Download .blend file

$\endgroup$
2
  • $\begingroup$ This is a bit of a programming recursion problem to implement, and a bit of a rightclickselect.com request to ask about here. To trace through all the modifiers and constraints could cause trouble in large or recursive systems. $\endgroup$
    – TheLabCat
    Oct 15, 2021 at 2:56
  • 1
    $\begingroup$ Thanks for your suggestion, if this select feature it not already on blender, i hope someone can share the script here $\endgroup$
    – cheatPKL
    Oct 16, 2021 at 23:14

1 Answer 1

1
$\begingroup$

I don't think you're going to get a complete script for this, and no the function doesn't exist in Blender by default.

The basic function is easy to design and here it is in pseudocode:

examined = set()
to_examine = [bpy.context.active_object]

while to_examine:

    object = to_examine[0]
    to_examine.remove(object)

    for new_object in EACH_OBJECT_RELATED_TO_OBJECT:
        if not new_object in examined:
            to_examine.append(new_object)

for object in examined:
    object.select_set(True)

This is a common pattern when you are walking a tree but only need to know the names of the nodes. Every time it encounters an object it hasn't seen before, it adds it to the list of objects it needs to process (to_examine). Whenever it wants to process an object it removes it from that list.

Each time it finishes processing an object it remembers the object by adding it to the examined set.

At the end, every object that is related to the original object is in the examined set.

The real problem is EACH_OBJECT_RELATED_TO_OBJECT. You need to evaluate every aspect of the original object, like parenting, children, modifiers, et cetera, to see if that aspect turns up an object.

But that code is tedious to write, and very fragile. For instance, here's a tiny fragment of code to find the objects related because they're in a modifier:

def get_modifier_object(modifier):
    if modifier.type == 'BOOLEAN':
        return modifier.object
    if modifier.type == 'MIRROR':
        return modifier.mirror_object
    return None

That happens to handle the two modifiers in your object, but to be complete, there needs to be an if for every modifier type, that either does nothing, because the modifier doesn't use another object, or returns the modifier's object, and every modifier that has an object identifies it through a different property.

So the final script would be full of functions to identify modifiers by type, constraints by type, et cetera and return any objects used by those pieces.

$\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.