Welcome to mirror list, hosted at ThFree Co, Russian Federation.

git.blender.org/blender.git - Unnamed repository; edit this file 'description' to name the repository.
summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
Diffstat (limited to 'release/scripts/modules/animsys_refactor.py')
-rw-r--r--release/scripts/modules/animsys_refactor.py89
1 files changed, 48 insertions, 41 deletions
diff --git a/release/scripts/modules/animsys_refactor.py b/release/scripts/modules/animsys_refactor.py
index 8cc91873b0e..464df870e87 100644
--- a/release/scripts/modules/animsys_refactor.py
+++ b/release/scripts/modules/animsys_refactor.py
@@ -22,11 +22,12 @@
This module has utility functions for renaming
rna values in fcurves and drivers.
-The main function to use is: update_data_paths(...)
+The main function to use is: update_data_paths(...)
"""
IS_TESTING = False
+
class DataPathBuilder(object):
__slots__ = ("data_path", )
""" Dummy class used to parse fcurve and driver data paths.
@@ -37,7 +38,7 @@ class DataPathBuilder(object):
def __getattr__(self, attr):
str_value = ".%s" % attr
return DataPathBuilder(self.data_path + (str_value, ))
-
+
def __getitem__(self, key):
str_value = '["%s"]' % key
return DataPathBuilder(self.data_path + (str_value, ))
@@ -51,7 +52,7 @@ class DataPathBuilder(object):
if base is not Ellipsis:
try:
# this only works when running with an old blender
- # where the old path will resolve
+ # where the old path will resolve
base = eval("base" + item)
except:
base_new = Ellipsis
@@ -61,7 +62,7 @@ class DataPathBuilder(object):
try:
print("base." + item_new)
base_new = eval("base." + item_new)
- break # found, dont keep looking
+ break # found, dont keep looking
except:
pass
@@ -77,7 +78,7 @@ import bpy
def id_iter():
type_iter = type(bpy.data.objects)
-
+
for attr in dir(bpy.data):
data_iter = getattr(bpy.data, attr, None)
if type(data_iter) == type_iter:
@@ -111,16 +112,17 @@ def classes_recursive(base_type, clss=None):
def find_path_new(id_data, data_path, rna_update_dict, rna_update_from_map):
+ # note!, id_data can be ID type or a node tree
# ignore ID props for now
if data_path.startswith("["):
return data_path
-
+
# recursive path fixing, likely will be one in most cases.
data_path_builder = eval("DataPathBuilder(tuple())." + data_path)
data_resolve = data_path_builder.resolve(id_data, rna_update_from_map)
path_new = [pair[0] for pair in data_resolve]
-
+
# print(data_resolve)
data_base = id_data
@@ -137,55 +139,60 @@ def find_path_new(id_data, data_path, rna_update_dict, rna_update_from_map):
# set this as the base for further properties
data_base = data
-
- data_path_new = "".join(path_new)[1:] # skip the first "."
+
+ data_path_new = "".join(path_new)[1:] # skip the first "."
return data_path_new
def update_data_paths(rna_update):
''' rna_update triple [(class_name, from, to), ...]
'''
-
+
# make a faster lookup dict
rna_update_dict = {}
for ren_class, ren_from, ren_to in rna_update:
rna_update_dict.setdefault(ren_class, {})[ren_from] = ren_to
-
+
rna_update_from_map = {}
for ren_class, ren_from, ren_to in rna_update:
rna_update_from_map.setdefault(ren_from, []).append(ren_to)
for id_data in id_iter():
- anim_data = getattr(id_data, "animation_data", None)
- if anim_data is None:
- continue
-
- for fcurve in anim_data.drivers:
- for var in fcurve.driver.variables:
- if var.type == 'SINGLE_PROP':
- for tar in var.targets:
- id_data_other = tar.id
- data_path = tar.data_path
-
- if id_data_other and data_path:
- data_path_new = find_path_new(id_data_other, data_path, rna_update_dict, rna_update_from_map)
- # print(data_path_new)
- if data_path_new != data_path:
- if not IS_TESTING:
- tar.data_path = data_path_new
- print("driver (%s): %s -> %s" % (id_data_other.name, data_path, data_path_new))
-
-
-
- for action in anim_data_actions(anim_data):
- for fcu in action.fcurves:
- data_path = fcu.data_path
- data_path_new = find_path_new(id_data, data_path, rna_update_dict, rna_update_from_map)
- # print(data_path_new)
- if data_path_new != data_path:
- if not IS_TESTING:
- fcu.data_path = data_path_new
- print("fcurve (%s): %s -> %s" % (id_data.name, data_path, data_path_new))
+
+ # check node-trees too
+ anim_data_ls = [(id_data, getattr(id_data, "animation_data", None))]
+ node_tree = getattr(id_data, "node_tree", None)
+ if node_tree:
+ anim_data_ls.append((node_tree, node_tree.animation_data))
+
+ for anim_data_base, anim_data in anim_data_ls:
+ if anim_data is None:
+ continue
+
+ for fcurve in anim_data.drivers:
+ for var in fcurve.driver.variables:
+ if var.type == 'SINGLE_PROP':
+ for tar in var.targets:
+ id_data_other = tar.id
+ data_path = tar.data_path
+
+ if id_data_other and data_path:
+ data_path_new = find_path_new(id_data_other, data_path, rna_update_dict, rna_update_from_map)
+ # print(data_path_new)
+ if data_path_new != data_path:
+ if not IS_TESTING:
+ tar.data_path = data_path_new
+ print("driver (%s): %s -> %s" % (id_data_other.name, data_path, data_path_new))
+
+ for action in anim_data_actions(anim_data):
+ for fcu in action.fcurves:
+ data_path = fcu.data_path
+ data_path_new = find_path_new(anim_data_base, data_path, rna_update_dict, rna_update_from_map)
+ # print(data_path_new)
+ if data_path_new != data_path:
+ if not IS_TESTING:
+ fcu.data_path = data_path_new
+ print("fcurve (%s): %s -> %s" % (id_data.name, data_path, data_path_new))
if __name__ == "__main__":