I've done an addon with a button that creates a color animation of sorts where the colors change with regular intervals. But my code only works for a cube. When I try to enable the code for selected objects the script runs fine, but when I press the button I'm getting an error:
Python: Traceback (most recent call last): line 84, in execute AttributeError: 'list' object has no attribute 'active_material'
What is wrong here?
The code for the color loop:
class COLORANIM_OT_my_operator(bpy.types.Operator):
"""Click OK and press space to start animation"""
bl_label = "Color Animation"
bl_idname = "coloranim.my_operator"
def execute(self, context):
mat = bpy.data.materials.new(name='colored')
obj = bpy.context.selected_objects
obj.active_material = mat
colors = [(1, 1, 0, 1), #yellow
(0, 1, 0, 1), #green
(0, 0.7, 1, 1), #blue
(0.7, 0, 1, 1), #purple
(1, 0, 0, 1), #red
(0, 0, 0, 1),] #black
frames = [1 , 30, 60, 90, 120, 150, 180]
for f, c in zip(frames, colors):
mat.diffuse_color = c
mat.keyframe_insert(data_path='diffuse_color', frame=f, index=-1)
return {'FINISHED'}
def invoke(self, context, event):
return context.window_manager.invoke_props_dialog(self)