1
$\begingroup$

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':
           bpy.ops.object.select_pattern(pattern=markers[c].attributes['camera'].value)
           override = bpy.context.copy()
           override['area'] = area
           bpy.context.scene.frame_set(int(markers[c].attributes['frame'].value))
           bpy.ops.marker.add(override)
           bpy.ops.marker.rename(override,name=markers[c].attributes['name'].value)
           bpy.ops.marker.camera_bind(override)
           bpy.ops.object.select_all(action='DESELECT')

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?

Thanks!

$\endgroup$
0
$\begingroup$

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"])
$\endgroup$

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.