Categories
Blender Scripting Stuff I made

Blender script – output markers and frames to CSV

I wrote a quickie script which exports timeline markers in a scene to a CSV folder along with their frame positions. My markers are named after shots, e.g. 04_04_C or 01_02_A2. I wanted to know how long the shots go for, but I didn’t want to figure it out by hand because that’s not how programmers roll.

import bpy
import csv
import os

C = bpy.context
markers = {}

for m in C.scene.timeline_markers:
    markers[m.frame] = m.name

k = list(markers.keys())
k.sort()
frameinfo = []

for frame in k:
    frameinfo.append( [markers[frame], frame] )

with open(os.path.splitext(bpy.data.filepath)[0]+'_frames.csv', 'w', newline='') as f:
    writer = csv.writer(f)
    writer.writerow( [ "Marker", "Frame" ] )
    for row in frameinfo:
        writer.writerow(row)

print("All done!")

You can copypaste this script straight into Blender’s text editor and hit “Run Script” to output filename_frames.csv in the directory right next to your currently open file. Yay!