Help needed with "Duplicate Object for Editing"

I have some shape keys on an object. What I want to be able to do is very simple;

1-Get the first key in the list and set it’s value to one,
2-Invoke the “Duplicate for Editing” command and get a clean copy of it
3-Move on to the next shape key and repeat through.

My problem is that the duplicated object that is created becomes the active object and since I can’t point to an object variable in “bpy.ops.object.object_duplicate_flatten_modifiers()”, the object created out in the first iteration gets clean duplicated over and over… I’m helpless :frowning:

Here’s my code:

import bpy


import bpy

ob=bpy.context.object

shape_key = ob.data.shape_keys
kbloks = shape_key.key_blocks

for shape in kbloks:
    ob.select = True
    shape.value = 1
    bpy.ops.object.object_duplicate_flatten_modifiers()
    shape.value = 0

Could anyone help me please?

you can set an object as active via

bpy.context.scene.objects.active

bpy.context.object is a shorthand, but read-only.

AARRRGHHH!!! I just can’t do it… :frowning: Could you be more specific please? Here’s my altered code:

import bpy

ob=bpy.context.object

shape_key = ob.data.shape_keys
kbloks = shape_key.key_blocks

for shape in kbloks:
    ob.select = True
    bpy.context.scene.objects.active
    shape.value = 1
    bpy.ops.object.object_duplicate_flatten_modifiers()
    shape.value = 0