在字符后声明所有内容
Declare everything after a character
我正在尝试为 Blender 编写一个 Python 脚本,它将删除所有以 KK
开头的形状键。
我有很多 shapekeys
以 KK
开头但在 KK
之后有不同的内容,例如 KK_Eyebrows
或 KK_Nose
我成功地使用了这个:
import bpy
def deleteShapekeyByName(oObject, sShapekeyName):
# setting the active shapekey
iIndex = oObject.data.shape_keys.key_blocks.keys().index(sShapekeyName)
oObject.active_shape_key_index = iIndex
# delete it
bpy.ops.object.shape_key_remove()
oActiveObject = bpy.context.active_object
deleteShapekeyByName(oActiveObject, "KK_Shapekey")
但我必须手动输入每个要删除的 shapekey
名称,而不是删除其中包含 KK
的所有名称。
提前致谢
如果您可以获得 shapekey 名称的列表,您可以执行类似的操作。
import bpy
def deleteShapekeyByName(oObject, sShapekeyName):
# setting the active shapekey
iIndex = oObject.data.shape_keys.key_blocks.keys().index(sShapekeyName)
oObject.active_shape_key_index = iIndex
# delete it
bpy.ops.object.shape_key_remove()
# Not sure if this returns the right keys for you. you may have to change .object to .active_object
s_key_names = list(bpy.context.object.data.shape_keys.key_blocks.keys())
oActiveObject = bpy.context.active_object
for s_k_n in s_key_names:
if s_k_n.startswith('KK'):
deleteShapekeyByName(oActiveObject, s_k_n)
我正在尝试为 Blender 编写一个 Python 脚本,它将删除所有以 KK
开头的形状键。
我有很多 shapekeys
以 KK
开头但在 KK
之后有不同的内容,例如 KK_Eyebrows
或 KK_Nose
我成功地使用了这个:
import bpy
def deleteShapekeyByName(oObject, sShapekeyName):
# setting the active shapekey
iIndex = oObject.data.shape_keys.key_blocks.keys().index(sShapekeyName)
oObject.active_shape_key_index = iIndex
# delete it
bpy.ops.object.shape_key_remove()
oActiveObject = bpy.context.active_object
deleteShapekeyByName(oActiveObject, "KK_Shapekey")
但我必须手动输入每个要删除的 shapekey
名称,而不是删除其中包含 KK
的所有名称。
提前致谢
如果您可以获得 shapekey 名称的列表,您可以执行类似的操作。
import bpy
def deleteShapekeyByName(oObject, sShapekeyName):
# setting the active shapekey
iIndex = oObject.data.shape_keys.key_blocks.keys().index(sShapekeyName)
oObject.active_shape_key_index = iIndex
# delete it
bpy.ops.object.shape_key_remove()
# Not sure if this returns the right keys for you. you may have to change .object to .active_object
s_key_names = list(bpy.context.object.data.shape_keys.key_blocks.keys())
oActiveObject = bpy.context.active_object
for s_k_n in s_key_names:
if s_k_n.startswith('KK'):
deleteShapekeyByName(oActiveObject, s_k_n)