Skip to content

Commit d004f1b

Browse files
committed
blender: Delete previous action button
Include a button that will delete the previous action. This is usefull when scripting a video frame by frame, and an action was insterted, only to realize it was not yet finished in the next frame.
1 parent 7d653af commit d004f1b

1 file changed

Lines changed: 33 additions & 4 deletions

File tree

funscripting.py

Lines changed: 33 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -65,7 +65,7 @@ def limitinfo(self, context):
6565
layout = self.layout
6666
row = layout.row(align=True)
6767
col = row.column(align=True)
68-
last = {"frame":0, "value":0}
68+
last = {"frame":1, "value":0}
6969
if keyframes is not None:
7070
for kf in reversed(keyframes):
7171
frame = kf.co[0]
@@ -76,17 +76,21 @@ def limitinfo(self, context):
7676
last = {"frame":frame, "value":value}
7777
break
7878
interval = frame_to_ms(scene.frame_current) - frame_to_ms(last["frame"])
79-
icon = "FILE_TICK" if interval > 100 or last["frame"] == 0 else "ERROR"
79+
icon = "FILE_TICK" if interval > 100 or last["frame"] == 1 else "ERROR"
8080
if interval > 1000:
8181
icon = "TIME"
8282
mindist = launch_distance(20, interval)
8383
maxdist = launch_distance(80, interval)
84+
8485
col.label(text="Previous: %d" % last["value"])
8586
col = row.column(align=True)
86-
col.label("Slowest: %d" % mindist)
87+
col.operator("funscript.delete", text="Delete").frame=last["frame"]
8788
row = layout.row(align=True)
8889
col = row.column(align=True)
8990
col.label(text="Interval: %d ms" % interval, icon=icon)
91+
row = layout.row(align=True)
92+
col = row.column(align=True)
93+
col.label("Slowest: %d" % mindist)
9094
col = row.column(align=True)
9195
col.label("Fastest: %d" % maxdist)
9296

@@ -126,7 +130,6 @@ class FunscriptPositionButton(bpy.types.Operator):
126130
launchPosition = bpy.props.IntProperty()
127131

128132
def execute(self, context):
129-
print("inserting: %d" % self.launchPosition)
130133
scene = context.scene
131134
if len(context.selected_sequences) < 1:
132135
self.report({'ERROR_INVALID_CONTEXT'}, "No sequence selected.")
@@ -136,6 +139,26 @@ def execute(self, context):
136139
scene.frame_set(scene.frame_current)
137140
return{'FINISHED'}
138141

142+
class FunscriptDeleteButton(bpy.types.Operator):
143+
"""Position delete button.
144+
145+
Button that deletes a Launch position from the currently selected Sequence.
146+
"""
147+
bl_idname = "funscript.delete"
148+
bl_label = "Delete"
149+
bl_options = {'REGISTER', 'UNDO'}
150+
frame = bpy.props.IntProperty()
151+
152+
def execute(self, context):
153+
scene = context.scene
154+
if len(context.selected_sequences) < 1:
155+
self.report({'ERROR_INVALID_CONTEXT'}, "No sequence selected.")
156+
return{'CANCELLED'}
157+
seq = context.selected_sequences[0]
158+
delete_position(seq, self.frame)
159+
scene.frame_set(scene.frame_current)
160+
return{'FINISHED'}
161+
139162
class FunscriptRepeatButton(bpy.types.Operator):
140163
"""Repeat last stroke button.
141164
@@ -261,6 +284,10 @@ def insert_position(seq, position, frame):
261284
seq["launch"] = position
262285
seq.keyframe_insert(data_path='["launch"]', frame=frame)
263286

287+
def delete_position(seq, frame):
288+
"""Deletes from seq a keyframe on frame."""
289+
seq.keyframe_delete(data_path='["launch"]', frame=frame)
290+
264291
def repeat_stroke(seq, frame_current):
265292
"""Repeat the last stroke on the current frame"""
266293
stroke = last_stroke(seq, frame_current)
@@ -369,6 +396,7 @@ def launch_distance(speed, duration):
369396

370397
def register():
371398
bpy.utils.register_class(FunscriptPositionButton)
399+
bpy.utils.register_class(FunscriptDeleteButton)
372400
bpy.utils.register_class(FunscriptRepeatButton)
373401
bpy.utils.register_class(FunscriptFillButton)
374402
bpy.utils.register_class(FunscriptExport)
@@ -461,6 +489,7 @@ def unregister():
461489
bpy.utils.unregister_class(FunscriptExport)
462490
bpy.utils.unregister_class(FunscriptFillButton)
463491
bpy.utils.unregister_class(FunscriptRepeatButton)
492+
bpy.utils.unregister_class(FunscriptDeleteButton)
464493
bpy.utils.unregister_class(FunscriptPositionButton)
465494

466495
if __name__ == "__main__":

0 commit comments

Comments
 (0)