[Bf-extensions-cvs] [e4d9cf84] master: Rigify: clear driver errors after generation.
Alexander Gavrilov
noreply at git.blender.org
Tue Jul 20 11:18:43 CEST 2021
Commit: e4d9cf84d00a6d223af3c89073858547090217ef
Author: Alexander Gavrilov
Date: Tue Jul 20 12:18:03 2021 +0300
Branches: master
https://developer.blender.org/rBAe4d9cf84d00a6d223af3c89073858547090217ef
Rigify: clear driver errors after generation.
In the process of re-generating a rig, drivers that reference it
from other objects can temporarily become invalid. This sets an
error flag in the driver, stopping its evaluation, so the error
doesn't clear out even when it becomes valid again.
To fix stuck drivers, loop over all objects in the file after
generation and refresh their drivers by fake modification.
===================================================================
M rigify/generate.py
M rigify/utils/mechanism.py
===================================================================
diff --git a/rigify/generate.py b/rigify/generate.py
index c6c9f3a9..aa9a9a84 100644
--- a/rigify/generate.py
+++ b/rigify/generate.py
@@ -29,6 +29,7 @@ from .utils.layers import ORG_LAYER, MCH_LAYER, DEF_LAYER, ROOT_LAYER
from .utils.naming import ORG_PREFIX, MCH_PREFIX, DEF_PREFIX, ROOT_NAME, make_original_name
from .utils.widgets import WGT_PREFIX
from .utils.widgets_special import create_root_widget
+from .utils.mechanism import refresh_all_drivers
from .utils.misc import gamma_correct, select_object
from .utils.collections import ensure_widget_collection, list_layer_collections, filter_layer_collections_by_object
from .utils.rig import get_rigify_type
@@ -540,6 +541,9 @@ class Generator(base_generate.BaseGenerator):
child.parent_bone = sub_parent
child.matrix_world = mat
+ # Clear any transient errors in drivers
+ refresh_all_drivers()
+
#----------------------------------
# Restore active collection
view_layer.active_layer_collection = self.layer_collection
diff --git a/rigify/utils/mechanism.py b/rigify/utils/mechanism.py
index 413d8a00..92e161f6 100644
--- a/rigify/utils/mechanism.py
+++ b/rigify/utils/mechanism.py
@@ -21,6 +21,8 @@
import bpy
import re
+from bpy.types import bpy_prop_collection, Material
+
from rna_prop_ui import rna_idprop_ui_create, rna_idprop_ui_prop_get
from rna_prop_ui import rna_idprop_quote_path as quote_property
@@ -518,6 +520,38 @@ def copy_custom_properties_with_ui(rig, src, dest_bone, *, ui_controls=None, **o
return mapping
+#=============================================
+# Driver management
+#=============================================
+
+def refresh_drivers(obj):
+ """Cause all drivers belonging to the object to be re-evaluated, clearing any errors."""
+
+ # Refresh object's own drivers if any
+ anim_data = getattr(obj, 'animation_data', None)
+
+ if anim_data:
+ for fcu in anim_data.drivers:
+ # Make a fake change to the driver
+ fcu.driver.type = fcu.driver.type
+
+ # Material node trees aren't in any lists
+ if isinstance(obj, Material):
+ refresh_drivers(obj.node_tree)
+
+
+def refresh_all_drivers():
+ """Cause all drivers in the file to be re-evaluated, clearing any errors."""
+
+ # Iterate over all datablocks in the file
+ for attr in dir(bpy.data):
+ coll = getattr(bpy.data, attr, None)
+
+ if isinstance(coll, bpy_prop_collection):
+ for item in coll:
+ refresh_drivers(item)
+
+
#=============================================
# Utility mixin
#=============================================
More information about the Bf-extensions-cvs
mailing list