Pythonで以下のようなプログラムを作っています。
・グラフのを通る点のうち、その点における接線の傾きが0でない点を削除
グラフを通る点が
AjDuplFcrv[m].keyframe_points
に
AjDuplFcrv[m].keyframe_points[0],
AjDuplFcrv[m].keyframe_points[1],
....
と格納されているのですが、ループ処理内で点を削除してしまうとそれ以降の点のインデックスが繰り上げられてしまい、次のループに入った際に一つ点をスキップしてしまいます。
全ての点に対し処理をするにはどのように処理をすればよいでしょうか。
よろしくお願いします。
python
1import bpy 2import numpy as np 3 4 5class GraphMod(bpy.types.Operator): 6 bl_idname = "graph.modification" 7 bl_label = "Graph Modification" 8 bl_description = "Transform Graph" 9 bl_options = {'REGISTER', 'UNDO'} 10 11 def execute(self,context): 12 aj = bpy.context.scene.objects.active 13 shape_key = aj.data.shape_keys 14 kbloks = shape_key.key_blocks.keys()#basis,mouth,... 15 bpy.ops.object.duplicate()#複製 16 ajDup = bpy.context.scene.objects.active#複製を選択 17 18 animParamList = [getattr(aj.data, 'shape_keys', None)] 19 print(animParamList) 20 print(len(animParamList)) 21 print(animParamList[0]) 22 print(type(animParamList[0])) 23 24 action = animParamList[0].animation_data.action 25 26 m=0 27 for fc in action.fcurves: 28 AnimShps = [] 29 animfcrvDP = fc.data_path 30 animfcrvChName=animfcrvDP.split('"')[1]#名前を取り出す 31 AnimShps.append(animfcrvChName)#空のリストに名前を入れる 32 AnimShpIndL = [i for i, j in enumerate(kbloks) if j == animfcrvChName]#シェイプキーのインデックスを探す 33 AnimShpInd = AnimShpIndL[0]#インデックスを代入 34 bpy.context.object.active_shape_key_index = AnimShpInd#該当のシェイプキーを選択 35 36 ajDup.data.shape_keys.key_blocks[AnimShpInd].keyframe_insert("value") 37 AjDuplFcrv = ajDup.data.shape_keys.animation_data.action.fcurves 38 39#削除処理 40 for k, key in enumerate(AjDuplFcrv[m].keyframe_points):#グラフを通る点でループ 41 if(key.handle_left[1]!=key.handle_right[1]):#接線の傾きを判定 42 AjDuplFcrv[m].keyframe_points.remove(AjDuplFcrv[m].keyframe_points[k])#点を削除 43 44 45 m=m+1 46 47 return {'FINISHED'} 48 49 50def menu_func(self, context): 51 self.layout.operator("graph.modification") 52 53 54def register(): 55 bpy.utils.register_module(__name__) 56 bpy.types.GRAPH_MT_channel.append(menu_func) 57 bpy.types.DOPESHEET_MT_channel.append(menu_func) 58 print("installed add-on") 59 60 61def unregister(): 62 bpy.types.GRAPH_MT_channel.remove(menu_func) 63 bpy.types.DOPESHEET_MT_channel.remove(menu_func) 64 bpy.utils.unregister_module(__name__) 65 print("uninstalled add-on") 66 67 68if __name__ == "__main__": 69 register() 70
回答1件
あなたの回答
tips
プレビュー
バッドをするには、ログインかつ
こちらの条件を満たす必要があります。
2019/05/18 15:59