1
$\begingroup$

Is it possible to list, in Python, all the subtracted objects?

I've got a big wall (Wall) with 3 holes (Cube, Cube.001, Cube.002). I made the holes with a boolean difference and I wish to list the names of these objects.

In this case I want to list:

list = ['Cube', 'Cube.001', 'Cube.002']

Thanks in advance!

enter image description here

$\endgroup$

1 Answer 1

2
$\begingroup$

This script will loop through the modifiers on the specified object, check if they are boolean modifiers, check if the modifier has an object specified, and if it does it will print the name of the object being used:

import bpy

#Object with modifiers
object = bpy.data.objects['Cube']       

for modifier in object.modifiers:
    #Check if modifier is boolean AND has a boolean object selected  
    if modifier.type == "BOOLEAN" and modifier.object:
        print (modifier.object.name)

You could of course .append object names into a list instead of printing.

Alternatively, you can use a list comprehension version which does exactly the same, except this adds all object names to a list before printing:

objects = [mod.object.name for mod in object.modifiers if mod.type=="BOOLEAN" and mod.object]
print (objects)
$\endgroup$

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .