I'm developing a script that exports and imports timeline markers with binded cameras. Printing marker info and exporting are working fine. The problem is the last step of the import script.

This is the XML I'm trying to import:

<?xml version="1.0"?><root>
<timeline_marker name="F_00" frame="0" camera="Camera.003" frame_time="-0.04"></timeline_marker>
<timeline_marker name="F_335" frame="335" camera="Camera.005" frame_time="13.92"></timeline_marker>
<timeline_marker name="F_616" frame="616" camera="Camera.003" frame_time="25.62"></timeline_marker>
<timeline_marker name="F_1214" frame="1214" camera="Camera.001" frame_time="50.54"></timeline_marker>

The goal is to recreate the markers, the marker's name and binding the marker to the respective camera.

I got everything to work except the binding of the camera. Blender insists of using only the last camera. Here's the code I'm using:

for c in range(len(markers)):
    for area in bpy.context.screen.areas:
        if area.type == 'TIMELINE':
           override = bpy.context.copy()
           override['area'] = area

Cameras are being selected and deselected, but the binding is done only to the last one, for some reason.

My only clue right now is that the select operation is slower than the script and when the first select operation is performed it just catches the last camera. But if that is true, what is the code i should be using to select the camera?



1 Answer 1


You can do this quite simply without the bpy.ops. For testing I made a py dict from some of your xml data.

import bpy
context = bpy.context
scene = context.scene
markers = {
            "F_00": {"frame":0, "camera":"Camera.003", "frame_time":0.04},
            "F_335": {"frame":335, "camera":"Camera.005", "frame_time":13.92},
for name, m_data in markers.items():
    # add a marker 
    marker = scene.timeline_markers.new(name, frame=m_data["frame"])
    marker.camera = scene.objects.get(m_data["camera"])

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .