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?

  • $\begingroup$ Scripting would work, but might take some work to be automatic. Sounds like a decent rightclickselect.com feature request. $\endgroup$
    – TheLabCat
    Jul 21 at 2:48
  • $\begingroup$ 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"] $\endgroup$
    – batFINGER
    Jul 24 at 15:12

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:
            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), 
        ), None):
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.

  • $\begingroup$ Thanks, it helped me a lot. $\endgroup$ Jul 26 at 3:54

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.