def copy_custom_properties(src, dest, *, prefix='', dest_prefix='', link_driver=False, overridable=True): """Copy custom properties with filtering by prefix. Optionally link using drivers.""" res = [] exclude = {'_RNA_UI', 'rigify_parameters', 'rigify_type'} for key, value in src.items(): if key.startswith(prefix) and key not in exclude: new_key = dest_prefix + key[len(prefix):] info = rna_idprop_ui_prop_get(src, key, create=False) if src != dest or new_key != key: dest[new_key] = value if info: info2 = rna_idprop_ui_prop_get(dest, new_key, create=True) for ki, vi in info.items(): info2[ki] = vi if link_driver: make_driver(src, quote_property(key), variables=[(dest.id_data, dest, new_key)]) if overridable: dest.property_overridable_library_set(quote_property(new_key), True) res.append((key, new_key, value, info)) return res
def copy_custom_properties(src, dest, *, prefix='', dest_prefix='', link_driver=False, overridable=True): """Copy custom properties with filtering by prefix. Optionally link using drivers.""" res = [] # Exclude addon-defined properties. exclude = {prop.identifier for prop in src.bl_rna.properties if prop.is_runtime} for key, value in src.items(): if key.startswith(prefix) and key not in exclude: new_key = dest_prefix + key[len(prefix):] try: ui_data_src = src.id_properties_ui(key) except TypeError: # Some property types, eg. Python dictionaries # don't support id_properties_ui. continue if src != dest or new_key != key: dest[new_key] = value dest.id_properties_ui(new_key).update_from(ui_data_src) if link_driver: make_driver(src, quote_property(key), variables=[(dest.id_data, dest, new_key)]) if overridable: dest.property_overridable_library_set(quote_property(new_key), True) res.append((key, new_key, value)) return res
def _init_driver_target(drv_target, var_info, target_id): """Initialize a driver variable target from a specification.""" # Parse the simple list format for the common case. if isinstance(var_info, tuple): # [ (target_id,) subtarget, ...path ] # If target_id is supplied as parameter, allow omitting it if target_id is None or isinstance(var_info[0], bpy.types.ID): target_id, subtarget, *refs = var_info else: subtarget, *refs = var_info subtarget = force_lazy(subtarget) # Simple path string case. if len(refs) == 0: # [ (target_id,) path_str ] path = subtarget else: # If subtarget is a string, look up a bone in the target if isinstance(subtarget, str): subtarget = target_id.pose.bones[subtarget] if subtarget == target_id: path = '' else: path = subtarget.path_from_id() # Use ".foo" type path items verbatim, otherwise quote for item in refs: if isinstance(item, str): path += item if item[0] == '.' else quote_property(item) else: path += '[%r]' % (item) if path[0] == '.': path = path[1:] drv_target.id = target_id drv_target.data_path = path else: # { 'id': ..., ... } target_id = var_info.get('id', target_id) if target_id is not None: drv_target.id = target_id for tp, tv in var_info.items(): setattr(drv_target, tp, force_lazy(tv))