I have 11 shape keys but my script wont read above number 9 Here is the script:



import bpy

#get the selected object
selected_object = bpy.context.object

#add shapekeys
bpy.ops.object.shape_key_add(from_mix=False)
bpy.ops.object.shape_key_add(from_mix=False)
bpy.ops.object.shape_key_add(from_mix=False)
bpy.ops.object.shape_key_add(from_mix=False)
bpy.ops.object.shape_key_add(from_mix=False)
bpy.ops.object.shape_key_add(from_mix=False)
bpy.ops.object.shape_key_add(from_mix=False)
bpy.ops.object.shape_key_add(from_mix=False)
bpy.ops.object.shape_key_add(from_mix=False)
bpy.ops.object.shape_key_add(from_mix=False)
bpy.ops.object.shape_key_add(from_mix=False)
bpy.ops.object.shape_key_add(from_mix=False)

#get its shapekeys
shape_keys = selected_object.data.shape_keys.key_blocks

#loop through shapekeys and replace the names
for index, key in enumerate(shape_keys):
    if key.name != "Basis":
        key.name = "Key 0" + str(index)

#loop through shape keys and replace the names
for key in shape_keys:
    key.name = key.name.replace("Key 01", "Open_Jaw")
    key.name = key.name.replace("Key 02", "Lips_Corner_In.L")
    key.name = key.name.replace("Key 03", "Lips_Corner_Up.L")
    key.name = key.name.replace("Key 04", "Lips_Corner_Out.L")
    key.name = key.name.replace("Key 05", "Lips_Corner_Dw.L")
    key.name = key.name.replace("Key 06", "Lips_Roll_Top")
    key.name = key.name.replace("Key 07", "Lips_Roll_Bot")
    key.name = key.name.replace("Key 08", "Lips_Corner_In.R")
    key.name = key.name.replace("Key 09", "Lips_Corner_Up.R")
    key.name = key.name.replace("Key 010", "Lips_Corner_Out.R")
    key.name = key.name.replace("Key 011", "Lips_Corner_Dw.R")
What is happening is the replace("Key 01", "Open_Jaw") matches "Key 011" and replaces the start of the name with "Open_Jaw".

One option is to do the replaces in reverse so that "Key 011" is replaced before you search for "Key 01".

Another way is to create and name each shapekey as you create it. Using the index of -1 will give you the last item in the list.

bpy.ops.object.shape_key_add(from_mix=False)
shape_keys[-1].name = "Open_Jaw"
bpy.ops.object.shape_key_add(from_mix=False)
shape_keys[-1].name = "Lips_Corner_In.L"


Which you can simplify into looping through a list of shapekey names.

keynames = [
    "Open_Jaw",
    "Lips_Corner_In.L",
    "Lips_Corner_Up.L",
    "Lips_Corner_Out.L",
    "Lips_Corner_Dw.L",
    "Lips_Roll_Top",
    "Lips_Roll_Bot",
    "Lips_Corner_In.R",
    "Lips_Corner_Up.R",
    "Lips_Corner_Out.R",
    "Lips_Corner_Dw.R",
    ]

shape_keys = bpy.context.object.data.shape_keys.key_blocks
for n in keynames:
    bpy.ops.object.shape_key_add(from_mix=False)
    shape_keys[-1].name = n