Skip to main content
corrected .lower() placement
Source Link
kopei
  • 63
  • 5
# Add driver from 'selected' object to target 'active' object.
# Target values are shape_key values
# 
# ShapeKeys must be named after Object for the script to work:
#
#      selected Object     = Cube
#      selected Shape Keys = Cube_abcd
#
#      active Object       = Sphere
#      active Shape Keys   = Sphere_abcd
#      
# 1. Select all object candidates to receive a driver.
# 2. Select 'active' object as driver target. 
# 3. Run script. 

import bpy

selected_obj = bpy.context.selected_objects
selected_obj.remove(bpy.context.active_object)

active_obj = bpy.context.active_object
shapekey_list_string = str(active_obj.data.shape_keys.key_blocks.keys()).lower()


for obj in selected_obj:
    for key in obj.data.shape_keys.key_blocks:
        if key.name.lower().lstrip(obj.name.lower()) in shapekey_list_string:
            if not key.name == "Basis":
                skey_driver = key.driver_add('value')
                skey_driver.driver.type = 'AVERAGE'
                skey_driver.driver.show_debug_info = True
                if skey_driver.driver.variables:
                    for v in skey_driver.driver.variables:
                        skey_driver.driver.variables.remove(v)
                newVar = skey_driver.driver.variables.new()
                newVar.name = "value"
                newVar.type = 'SINGLE_PROP'
                newVar.targets[0].id_type = 'KEY'
                newVar.targets[0].id = active_obj.data.shape_keys
                newVar.targets[0].data_path = 'key_blocks["' + active_obj.name + key.name.lstrip(obj.name.lower())+ '"].value'
                skey_driver = key.driver_add('mute')
                skey_driver.driver.type = 'AVERAGE'
                skey_driver.driver.show_debug_info = True
                if skey_driver.driver.variables:
                    for v in skey_driver.driver.variables:
                        skey_driver.driver.variables.remove(v)
                newVar = skey_driver.driver.variables.new()
                newVar.name = "hide"
                newVar.type = 'SINGLE_PROP'
                newVar.targets[0].id_type = 'KEY'
                newVar.targets[0].id = active_obj.data.shape_keys
                newVar.targets[0].data_path = 'key_blocks["' + active_obj.name + key.name.lstrip(obj.name.lower())+ '"].mute'
# Add driver from 'selected' object to target 'active' object.
# Target values are shape_key values
# 
# ShapeKeys must be named after Object for the script to work:
#
#      selected Object     = Cube
#      selected Shape Keys = Cube_abcd
#
#      active Object       = Sphere
#      active Shape Keys   = Sphere_abcd
#      
# 1. Select all object candidates to receive a driver.
# 2. Select 'active' object as driver target. 
# 3. Run script. 

import bpy

selected_obj = bpy.context.selected_objects
selected_obj.remove(bpy.context.active_object)

active_obj = bpy.context.active_object
shapekey_list_string = str(active_obj.data.shape_keys.key_blocks.keys())


for obj in selected_obj:
    for key in obj.data.shape_keys.key_blocks:
        if key.name.lstrip(obj.name.lower()) in shapekey_list_string:
            if not key.name == "Basis":
                skey_driver = key.driver_add('value')
                skey_driver.driver.type = 'AVERAGE'
                skey_driver.driver.show_debug_info = True
                if skey_driver.driver.variables:
                    for v in skey_driver.driver.variables:
                        skey_driver.driver.variables.remove(v)
                newVar = skey_driver.driver.variables.new()
                newVar.name = "value"
                newVar.type = 'SINGLE_PROP'
                newVar.targets[0].id_type = 'KEY'
                newVar.targets[0].id = active_obj.data.shape_keys
                newVar.targets[0].data_path = 'key_blocks["' + active_obj.name + key.name.lstrip(obj.name.lower())+ '"].value'
                skey_driver = key.driver_add('mute')
                skey_driver.driver.type = 'AVERAGE'
                skey_driver.driver.show_debug_info = True
                if skey_driver.driver.variables:
                    for v in skey_driver.driver.variables:
                        skey_driver.driver.variables.remove(v)
                newVar = skey_driver.driver.variables.new()
                newVar.name = "hide"
                newVar.type = 'SINGLE_PROP'
                newVar.targets[0].id_type = 'KEY'
                newVar.targets[0].id = active_obj.data.shape_keys
                newVar.targets[0].data_path = 'key_blocks["' + active_obj.name + key.name.lstrip(obj.name.lower())+ '"].mute'
# Add driver from 'selected' object to target 'active' object.
# Target values are shape_key values
# 
# ShapeKeys must be named after Object for the script to work:
#
#      selected Object     = Cube
#      selected Shape Keys = Cube_abcd
#
#      active Object       = Sphere
#      active Shape Keys   = Sphere_abcd
#      
# 1. Select all object candidates to receive a driver.
# 2. Select 'active' object as driver target. 
# 3. Run script. 

import bpy

selected_obj = bpy.context.selected_objects
selected_obj.remove(bpy.context.active_object)

active_obj = bpy.context.active_object
shapekey_list_string = str(active_obj.data.shape_keys.key_blocks.keys()).lower()


for obj in selected_obj:
    for key in obj.data.shape_keys.key_blocks:
        if key.name.lower().lstrip(obj.name.lower()) in shapekey_list_string:
            if not key.name == "Basis":
                skey_driver = key.driver_add('value')
                skey_driver.driver.type = 'AVERAGE'
                skey_driver.driver.show_debug_info = True
                if skey_driver.driver.variables:
                    for v in skey_driver.driver.variables:
                        skey_driver.driver.variables.remove(v)
                newVar = skey_driver.driver.variables.new()
                newVar.name = "value"
                newVar.type = 'SINGLE_PROP'
                newVar.targets[0].id_type = 'KEY'
                newVar.targets[0].id = active_obj.data.shape_keys
                newVar.targets[0].data_path = 'key_blocks["' + active_obj.name + key.name.lstrip(obj.name.lower())+ '"].value'
                skey_driver = key.driver_add('mute')
                skey_driver.driver.type = 'AVERAGE'
                skey_driver.driver.show_debug_info = True
                if skey_driver.driver.variables:
                    for v in skey_driver.driver.variables:
                        skey_driver.driver.variables.remove(v)
                newVar = skey_driver.driver.variables.new()
                newVar.name = "hide"
                newVar.type = 'SINGLE_PROP'
                newVar.targets[0].id_type = 'KEY'
                newVar.targets[0].id = active_obj.data.shape_keys
                newVar.targets[0].data_path = 'key_blocks["' + active_obj.name + key.name.lstrip(obj.name.lower())+ '"].mute'
deleted 8 characters in body
Source Link
kopei
  • 63
  • 5
# Add driver from 'selected' object to target 'active' object.
# Target values are shape_key values
# 
# ShapeKeys must be named after Object for the script to work:
#
#      selected Object     = Cube
#      selected Shape Keys = Cube_abcd
#
#      active Object       = Sphere
#      active Shape Keys   = Sphere_abcd
#      
# 1. Select all object candidates to receive a driver.
# 2. Select 'active' object as driver target. 
# 3. Run script. 

import bpy

selected_obj = bpy.context.selected_objects
selected_obj.remove(bpy.context.active_object)

active_obj = bpy.context.active_object
shapekey_list_string = str(active_obj.data.shape_keys.key_blocks.keys()).lower()


for obj in selected_obj:
    for key in obj.data.shape_keys.key_blocks:
        if key.name.lstrip(obj.name.lower()) in shapekey_list_string:
            if not key.name == "Basis":
                skey_driver = key.driver_add('value')
                skey_driver.driver.type = 'AVERAGE'
                skey_driver.driver.show_debug_info = True
                if skey_driver.driver.variables:
                    for v in skey_driver.driver.variables:
                        skey_driver.driver.variables.remove(v)
                newVar = skey_driver.driver.variables.new()
                newVar.name = "value"
                newVar.type = 'SINGLE_PROP'
                newVar.targets[0].id_type = 'KEY'
                newVar.targets[0].id = active_obj.data.shape_keys
                newVar.targets[0].data_path = 'key_blocks["' + active_obj.name + key.name.lstrip(obj.name.lower())+ '"].value'
                skey_driver = key.driver_add('mute')
                skey_driver.driver.type = 'AVERAGE'
                skey_driver.driver.show_debug_info = True
                if skey_driver.driver.variables:
                    for v in skey_driver.driver.variables:
                        skey_driver.driver.variables.remove(v)
                newVar = skey_driver.driver.variables.new()
                newVar.name = "hide"
                newVar.type = 'SINGLE_PROP'
                newVar.targets[0].id_type = 'KEY'
                newVar.targets[0].id = active_obj.data.shape_keys
                newVar.targets[0].data_path = 'key_blocks["' + active_obj.name + key.name.lstrip(obj.name.lower())+ '"].mute'
# Add driver from 'selected' object to target 'active' object.
# Target values are shape_key values
# 
# ShapeKeys must be named after Object for the script to work:
#
#      selected Object     = Cube
#      selected Shape Keys = Cube_abcd
#
#      active Object       = Sphere
#      active Shape Keys   = Sphere_abcd
#      
# 1. Select all object candidates to receive a driver.
# 2. Select 'active' object as driver target. 
# 3. Run script. 

import bpy

selected_obj = bpy.context.selected_objects
selected_obj.remove(bpy.context.active_object)

active_obj = bpy.context.active_object
shapekey_list_string = str(active_obj.data.shape_keys.key_blocks.keys()).lower()


for obj in selected_obj:
    for key in obj.data.shape_keys.key_blocks:
        if key.name.lstrip(obj.name.lower()) in shapekey_list_string:
            if not key.name == "Basis":
                skey_driver = key.driver_add('value')
                skey_driver.driver.type = 'AVERAGE'
                skey_driver.driver.show_debug_info = True
                if skey_driver.driver.variables:
                    for v in skey_driver.driver.variables:
                        skey_driver.driver.variables.remove(v)
                newVar = skey_driver.driver.variables.new()
                newVar.name = "value"
                newVar.type = 'SINGLE_PROP'
                newVar.targets[0].id_type = 'KEY'
                newVar.targets[0].id = active_obj.data.shape_keys
                newVar.targets[0].data_path = 'key_blocks["' + active_obj.name + key.name.lstrip(obj.name.lower())+ '"].value'
                skey_driver = key.driver_add('mute')
                skey_driver.driver.type = 'AVERAGE'
                skey_driver.driver.show_debug_info = True
                if skey_driver.driver.variables:
                    for v in skey_driver.driver.variables:
                        skey_driver.driver.variables.remove(v)
                newVar = skey_driver.driver.variables.new()
                newVar.name = "hide"
                newVar.type = 'SINGLE_PROP'
                newVar.targets[0].id_type = 'KEY'
                newVar.targets[0].id = active_obj.data.shape_keys
                newVar.targets[0].data_path = 'key_blocks["' + active_obj.name + key.name.lstrip(obj.name.lower())+ '"].mute'
# Add driver from 'selected' object to target 'active' object.
# Target values are shape_key values
# 
# ShapeKeys must be named after Object for the script to work:
#
#      selected Object     = Cube
#      selected Shape Keys = Cube_abcd
#
#      active Object       = Sphere
#      active Shape Keys   = Sphere_abcd
#      
# 1. Select all object candidates to receive a driver.
# 2. Select 'active' object as driver target. 
# 3. Run script. 

import bpy

selected_obj = bpy.context.selected_objects
selected_obj.remove(bpy.context.active_object)

active_obj = bpy.context.active_object
shapekey_list_string = str(active_obj.data.shape_keys.key_blocks.keys())


for obj in selected_obj:
    for key in obj.data.shape_keys.key_blocks:
        if key.name.lstrip(obj.name.lower()) in shapekey_list_string:
            if not key.name == "Basis":
                skey_driver = key.driver_add('value')
                skey_driver.driver.type = 'AVERAGE'
                skey_driver.driver.show_debug_info = True
                if skey_driver.driver.variables:
                    for v in skey_driver.driver.variables:
                        skey_driver.driver.variables.remove(v)
                newVar = skey_driver.driver.variables.new()
                newVar.name = "value"
                newVar.type = 'SINGLE_PROP'
                newVar.targets[0].id_type = 'KEY'
                newVar.targets[0].id = active_obj.data.shape_keys
                newVar.targets[0].data_path = 'key_blocks["' + active_obj.name + key.name.lstrip(obj.name.lower())+ '"].value'
                skey_driver = key.driver_add('mute')
                skey_driver.driver.type = 'AVERAGE'
                skey_driver.driver.show_debug_info = True
                if skey_driver.driver.variables:
                    for v in skey_driver.driver.variables:
                        skey_driver.driver.variables.remove(v)
                newVar = skey_driver.driver.variables.new()
                newVar.name = "hide"
                newVar.type = 'SINGLE_PROP'
                newVar.targets[0].id_type = 'KEY'
                newVar.targets[0].id = active_obj.data.shape_keys
                newVar.targets[0].data_path = 'key_blocks["' + active_obj.name + key.name.lstrip(obj.name.lower())+ '"].mute'
added .lower() to avoid script errors
Source Link
kopei
  • 63
  • 5
# Add driver from 'selected' object to target 'active' object.
# Target values are shape_key values
# 
# ShapeKeys must be named after Object for the script to work:
#
#      selected Object     = Cube
#      selected Shape Keys = Cube_abcd
#
#      active Object       = Sphere
#      active Shape Keys   = Sphere_abcd
#      
# 1. Select all object candidates to receive a driver.
# 2. Select 'active' object as driver target. 
# 3. Run script. 

import bpy

selected_obj = bpy.context.selected_objects
selected_obj.remove(bpy.context.active_object)

active_obj = bpy.context.active_object
shapekey_list_string = str(active_obj.data.shape_keys.key_blocks.keys()).lower()


for obj in selected_obj:
    if not obj == active_obj:
        for key in obj.data.shape_keys.key_blocks:
            if key.name.lstrip(obj.name.lower()) in shapekey_list_string:
                if not key.name == "Basis":
                    skey_driver = key.driver_add('value')
                    skey_driver.driver.type = 'AVERAGE'
                    skey_driver.driver.show_debug_info = True
                    if skey_driver.driver.variables:
                        for v in skey_driver.driver.variables:
                            skey_driver.driver.variables.remove(v)
                    newVar = skey_driver.driver.variables.new()
                newVar.name = "value"
                newVar.nametype = "var"'SINGLE_PROP'
                newVar.targets[0].id_type = 'KEY'
                newVar.targets[0].id = active_obj.data.shape_keys
                newVar.targets[0].data_path = 'key_blocks["' + active_obj.name + key.name.lstrip(obj.name.lower())+ '"].value'
                skey_driver = key.driver_add('mute')
                skey_driver.driver.type = 'SINGLE_PROP''AVERAGE'
                skey_driver.driver.show_debug_info = True
                if skey_driver.driver.variables:
                    for v in skey_driver.driver.variables:
                        skey_driver.driver.variables.remove(v)
                newVar = skey_driver.driver.variables.new()
                newVar.targets[0]name = "hide"
                newVar.id_typetype = 'KEY''SINGLE_PROP'
                newVar.targets[0].id_type = 'KEY'
                newVar.targets[0].id = active_obj.data.shape_keys
                    newVar.targets[0].data_path = 'key_blocks["' + active_obj.name + key.name.lstrip(obj.name.lower())+ '"].value'mute'
# Add driver from 'selected' object to target 'active' object.
# Target values are shape_key values
# 
# ShapeKeys must be named after Object for the script to work:
#
#      selected Object     = Cube
#      selected Shape Keys = Cube_abcd
#
#      active Object       = Sphere
#      active Shape Keys   = Sphere_abcd
#      
# 1. Select all object candidates to receive a driver.
# 2. Select 'active' object as driver target. 
# 3. Run script. 

import bpy

selected_obj = bpy.context.selected_objects
active_obj = bpy.context.active_object
shapekey_list_string = str(active_obj.data.shape_keys.key_blocks.keys())


for obj in selected_obj:
    if not obj == active_obj:
        for key in obj.data.shape_keys.key_blocks:
            if key.name.lstrip(obj.name) in shapekey_list_string:
                if not key.name == "Basis":
                    skey_driver = key.driver_add('value')
                    skey_driver.driver.type = 'AVERAGE'
                    skey_driver.driver.show_debug_info = True
                    if skey_driver.driver.variables:
                        for v in skey_driver.driver.variables:
                            skey_driver.driver.variables.remove(v)
                    newVar = skey_driver.driver.variables.new()
                    newVar.name = "var"
                    newVar.type = 'SINGLE_PROP'
                    newVar.targets[0].id_type = 'KEY'
                    newVar.targets[0].id = active_obj.data.shape_keys
                    newVar.targets[0].data_path = 'key_blocks["' + active_obj.name + key.name.lstrip(obj.name)+ '"].value'
# Add driver from 'selected' object to target 'active' object.
# Target values are shape_key values
# 
# ShapeKeys must be named after Object for the script to work:
#
#      selected Object     = Cube
#      selected Shape Keys = Cube_abcd
#
#      active Object       = Sphere
#      active Shape Keys   = Sphere_abcd
#      
# 1. Select all object candidates to receive a driver.
# 2. Select 'active' object as driver target. 
# 3. Run script. 

import bpy

selected_obj = bpy.context.selected_objects
selected_obj.remove(bpy.context.active_object)

active_obj = bpy.context.active_object
shapekey_list_string = str(active_obj.data.shape_keys.key_blocks.keys()).lower()


for obj in selected_obj:
    for key in obj.data.shape_keys.key_blocks:
        if key.name.lstrip(obj.name.lower()) in shapekey_list_string:
            if not key.name == "Basis":
                skey_driver = key.driver_add('value')
                skey_driver.driver.type = 'AVERAGE'
                skey_driver.driver.show_debug_info = True
                if skey_driver.driver.variables:
                    for v in skey_driver.driver.variables:
                        skey_driver.driver.variables.remove(v)
                newVar = skey_driver.driver.variables.new()
                newVar.name = "value"
                newVar.type = 'SINGLE_PROP'
                newVar.targets[0].id_type = 'KEY'
                newVar.targets[0].id = active_obj.data.shape_keys
                newVar.targets[0].data_path = 'key_blocks["' + active_obj.name + key.name.lstrip(obj.name.lower())+ '"].value'
                skey_driver = key.driver_add('mute')
                skey_driver.driver.type = 'AVERAGE'
                skey_driver.driver.show_debug_info = True
                if skey_driver.driver.variables:
                    for v in skey_driver.driver.variables:
                        skey_driver.driver.variables.remove(v)
                newVar = skey_driver.driver.variables.new()
                newVar.name = "hide"
                newVar.type = 'SINGLE_PROP'
                newVar.targets[0].id_type = 'KEY'
                newVar.targets[0].id = active_obj.data.shape_keys
                newVar.targets[0].data_path = 'key_blocks["' + active_obj.name + key.name.lstrip(obj.name.lower())+ '"].mute'
Source Link
kopei
  • 63
  • 5
Loading