1

So I have an issue with renaming Custom properties that are being used in a driver. As an example, I made a custom property for some drivers. But when I renamed the properties, the drivers associated with the properties just stopped working, and I need to manually change the data path of each driver. Is there a way to change the property's name without needing to manually change each data path? Meaning that each driver that has the properties data path will rename itself.

I also have some concerns if this issue also happened when I renamed other things such as bones. How do I rename it without breaking all the drivers I made?

  • Scripting would work, but might take some work to be automatic. Sounds like a decent rightclickselect.com feature request. – TheLabCat Jul 21 '21 at 02:48
  • Can it be assumed that the usage of the prop in the driver is as a SINGLE PROPERTY type variable target, with data_path set to eg ["prop"] – batFINGER Jul 24 '21 at 15:12

1 Answers1

1

Rename all single prop variable targets using custom prop.

Code slapped together from How to find out what is using an image in a blend file

Searches thru every driver in the blend file and renames "oldname" to "newname"

Test script below, with example call renaming and single property driver variables targets from ["prop"] to ["length"] Edit last line to suit.

import bpy
from bpy.types import bpy_prop_collection

def rename(oldname, newname):

def rename(col):
    for o in col:
        ad = getattr(o, "animation_data", None)
        if not ad:
            continue
        for d in ad.drivers:
            for v in d.driver.variables:
                if (
                    v.type == 'SINGLE_PROP'
                    and v.targets[0].data_path == f'["{oldname}"]' ):

                    v.targets[0].data_path = f'["{newname}"]'
while next(filter(None, (
    rename(getattr(bpy.data, p)) 
    for p in  dir(bpy.data) 
    if isinstance(
            getattr(bpy.data, p, None), 
            bpy_prop_collection
            )                
    )
    ), None):
        continue

x = rename("prop", "length")

PS excuse round about way of the script, a better logic would be to return the object, driver, target tuples of matches.

batFINGER
  • 84,216
  • 10
  • 108
  • 233