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.
This commit is contained in:
Alexander Gavrilov 2021-07-20 12:18:03 +03:00
parent 1adb56d8b0
commit e4d9cf84d0
2 changed files with 38 additions and 0 deletions

View File

@ -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

View File

@ -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
#=============================================