3
$\begingroup$

I have a complex file with a lot of objects in it. Many of them are there as a target for a modifier of some kind Boolean, curve modifier, etc. Sometimes I go through and clean out objects that are no longer needed. The problem is that it isn't always apparent if the object is being used in another object's modifier stack. I don't want to break my work only to find out a day later that I deleted something important.

Is there some way that I can quickly see if the object is being used?

$\endgroup$
3
  • $\begingroup$ @batFINGER oh man there really isn't any Python question you haven't already answered ^^ Didn't search enough on this one :) $\endgroup$
    – Gorgious
    Mar 16 '21 at 8:06
  • $\begingroup$ There are plenty. Have a good memory for answers. Marking as dupe helps link them together, to assist searching. (Sometimes I know there's a dupe but can't find.... ) Three good answers each doing it a little differently. (btw could lose the None test as it will never be an instance of Object) $\endgroup$
    – batFINGER
    Mar 16 '21 at 8:17
  • $\begingroup$ I don't think this should have been closed as a dupe, as it's actually the inverse of the linked question. Instead of knowing the modifiers and wanting to find the target, the question here is how to check for modifiers when you already know the target. The time complexity of iterating through every object in a file to check if they use a given object means that the algorithms for the former are of limited and messy applicability to the latter— And even then, would best be combined with other techniques (sets, dicts) that aren't mentioned in the linked post. $\endgroup$
    – Will Chen
    Mar 24 '21 at 23:49
4
$\begingroup$

I thought that objects used as a target in a modifier had their user count incremented but apparently not.

I'd use a script for that :

You can loop through all objects and all their modifiers and check what objects are linked to modifier fields. The following script will deselect all objects and select only objects that appear inside the target field of a modifier.

import bpy

bpy.ops.object.select_all(action='DESELECT')
# Deselect all objects

for obj in (o for o in bpy.data.objects if hasattr(o, "modifiers")):
    # Loop through all objects that actually support modifiers
    for mod in obj.modifiers:
        # Loop through all modifier(s) of that object
        for attr in dir(mod):
            # Loop through all attributes of that modifier 
            target = getattr(mod, attr)
            # Get the value of that attribute field
            if isinstance(target, bpy.types.Object) and target is not None:  
                # Filter in only attributes that link to an Object          
                target.select_set(True)

How to run a script in blender

Note :

On some instances object fields retain their object link even when the linked object is not actually used.

Example : On the boolean modifier, if you first use an Object as a target, then set the type to Collection, the link to the Object still remains. If you switch back to the Object type, you see that the target is still filled in. You'd have to add in special use cases for that in the script if that behaviour bothers you.

$\endgroup$
1
  • $\begingroup$ Wow, that is incredibly helpful. I guess I had better stop putting off learning how to code for blender. Thanks for your help. $\endgroup$
    – Michael
    Mar 15 '21 at 21:21

Not the answer you're looking for? Browse other questions tagged or ask your own question.