I’ve been trying to create a sound visualisation with the help of the Blender Cookie tutorial by Patrick Boelens and at the moment my script works fine. However, if I select all of my objects to animate and scale them using individual origins parallel to their local z-axes, and I try running my script I get an error at
bpy.context.active_object.animation_data.action.fcurves[0].lock = True
which says AttributeError: ‘NoneType’ object has no attribute ‘action’. Here is my full script:
def insert(item):
i = 0
sorting = True
while ((sorting) and (i < len(items) - 1)):
if (item.location.y <= items[i].location.y):
sorting = False
items.append(items[len(items) - 1])
j = len(items) - 2
while (j >= i):
items[j+1] = items[j]
j-=1
items[i] = item
i+=1
if (i >= len(items) - 1):
items.append(item)
import bpy
bpy.ops.object.select_all(action='DESELECT')
items = []
for object in bpy.data.groups['Things'].objects:
object.select = True
bpy.ops.object.transform_apply(location=False, rotation=False, scale=True)
bpy.ops.anim.keyframe_insert_menu(type='Scaling')
bpy.context.active_object.animation_data.action.fcurves[0].lock = True
bpy.context.active_object.animation_data.action.fcurves[1].lock = True
insert(object)
object.select = False
bpy.ops.object.select_all(action='DESELECT')
bpy.context.area.type = 'GRAPH_EDITOR'
step = 16000 / len(items)
i = 0
for object in items:
object.select = True
bpy.ops.graph.sound_bake(filepath="/home/Music File.mp3", low=i * step, high=(i + 1) * step)
object.select = False
i+=1
Why does this error only just happen after scaling and how can I fix it?
Thanks.