[Blender][スクリプト]シーケンサーで選択中のストリップの尺を表示する
シーケンサーで選択中のストリップの尺をサイドバーの「カスタム」というパネルに表示します。
フレーム数のみバージョン
import bpy
class SEQUENCER_PT_selected_strip_duration(bpy.types.Panel):
"""Selected Sequencer Strip Duration Panel"""
bl_label = "Selected Strip Duration"
bl_space_type = 'SEQUENCE_EDITOR'
bl_region_type = 'UI'
bl_category = 'Custom'
def draw(self, context):
layout = self.layout
scene = context.scene
sequencer = scene.sequence_editor
if sequencer:
# 選択中のストリップを取得
selected_strips = [s for s in sequencer.sequences_all if s.select]
if selected_strips:
for strip in selected_strips:
duration = strip.frame_final_duration
row = layout.row()
row.label(text=f"{strip.name}: {duration} frames")
else:
layout.label(text="No selected strips.")
else:
layout.label(text="Sequencer is not active.")
def register():
bpy.utils.register_class(SEQUENCER_PT_selected_strip_duration)
def unregister():
bpy.utils.unregister_class(SEQUENCER_PT_selected_strip_duration)
if __name__ == "__main__":
register()
分:秒:フレーム数バージョン
import bpy
class SEQUENCER_PT_selected_strip_duration(bpy.types.Panel):
"""Selected Sequencer Strip Duration Panel"""
bl_label = "Selected Strip Duration"
bl_space_type = 'SEQUENCE_EDITOR'
bl_region_type = 'UI'
bl_category = 'Custom'
def draw(self, context):
layout = self.layout
scene = context.scene
sequencer = scene.sequence_editor
fps = scene.render.fps # シーンのフレームレートを取得
if sequencer:
# 選択中のストリップを取得
selected_strips = [s for s in sequencer.sequences_all if s.select]
if selected_strips:
for strip in selected_strips:
duration = strip.frame_final_duration
# 分、秒、フレームを計算
total_seconds = duration / fps
minutes = total_seconds // 60
seconds = total_seconds % 60
frames = duration % fps
# 結果を「分:秒 + フレーム」の形式で表示
formatted_duration = f"{int(minutes):02d}:{int(seconds):02d}+{frames:02d}f"
row = layout.row()
row.label(text=f"{strip.name}: {formatted_duration}")
else:
layout.label(text="No selected strips.")
else:
layout.label(text="Sequencer is not active.")
def register():
bpy.utils.register_class(SEQUENCER_PT_selected_strip_duration)
def unregister():
bpy.utils.unregister_class(SEQUENCER_PT_selected_strip_duration)
if __name__ == "__main__":
register()
分:秒:フレーム数(無換算フレーム数)バージョン
import bpy
class SEQUENCER_PT_selected_strip_duration(bpy.types.Panel):
"""Selected Sequencer Strip Duration Panel"""
bl_label = "Selected Strip Duration"
bl_space_type = 'SEQUENCE_EDITOR'
bl_region_type = 'UI'
bl_category = 'Custom'
def draw(self, context):
layout = self.layout
scene = context.scene
sequencer = scene.sequence_editor
fps = scene.render.fps # シーンのフレームレートを取得
if sequencer:
# 選択中のストリップを取得
selected_strips = [s for s in sequencer.sequences_all if s.select]
if selected_strips:
for strip in selected_strips:
duration = strip.frame_final_duration
# 分、秒、フレームを計算
total_seconds = duration / fps
minutes = total_seconds // 60
seconds = total_seconds % 60
frames = duration % fps
# 元のフレーム数を表示
formatted_duration = f"{int(minutes):02d}:{int(seconds):02d}+{frames:02d}f({duration}f)"
row = layout.row()
row.label(text=f"{strip.name}: {formatted_duration}")
else:
layout.label(text="No selected strips.")
else:
layout.label(text="Sequencer is not active.")
def register():
bpy.utils.register_class(SEQUENCER_PT_selected_strip_duration)
def unregister():
bpy.utils.unregister_class(SEQUENCER_PT_selected_strip_duration)
if __name__ == "__main__":
register()
この記事が気に入ったらサポートをしてみませんか?