1
$\begingroup$

In the Movie-clip-editor: Is it possible to make a button for adding a marker with a pre-defined name? The code below I build a custom menu with button-names defined in a text-file. When clicked on a button you need to add a marker. The goal is to give that marker the name defined in the text-file. But for now just giving it a custom name (not Track.xxx) is OK. I can not find a way to change the name when markers are created. So I tought of a workaround wich just renames a track/marker called "Track" to the custom name. But that code is executed before "add_marker_at_click()" is finished.

from __future__ import print_function
import bpy
import os
class addmarkers(bpy.types.Operator):
    """ This operator adds markers
        add marker and give it a good name
    """
    bl_idname = "wm.addmarkers"
    bl_label = "addmarkers"

    def execute(self, context):
        # lmc to add a marker and change the name of the track

        bl_space_type='CLIP_EDITOR'

        sc=context.space_data
        clip=sc.clip        
        bpy.ops.clip.add_marker_at_click('INVOKE_DEFAULT') #click to add a marker



        #bpy.data.movieclips["test.avi"].tracking.tracks["Track"].name="TESTNAME"
        #previous line is executed before add_marker_at_click is finished, so it doesn't work
        return {'FINISHED'}

    def invoke(self, context, event):
        return self.execute(context)



class MARKERPANEL(bpy.types.Panel):
    bl_label = "Add markers"
    bl_space_type = "CLIP_EDITOR"
    bl_region_type = "TOOLS"
    bl_category = "MARKERPANEL"


    def draw(self, context):
        f = open('settings.txt', 'rt')

        for line in f:        

            layout = self.layout
            row = layout.row()

            sc = context.space_data
            clip = context.space_data.clip
            row.operator("wm.addmarkers", text=line)

bpy.utils.register_class(addmarkers)
bpy.utils.unregister_class(addmarkers)       
bpy.utils.register_class(MARKERPANEL)
bpy.utils.unregister_class(MARKERPANEL)   
bpy.utils.register_module(__name__)

for information: picture of the custom menu Custom Menu Markers

$\endgroup$
1
$\begingroup$

add_marker_at_click() is modal operator so it seems that it returns 'RUNNING_MODAL' and keeps running (waiting for user interactions) while your operator will finish without waiting for it , so I have used add_marker() instead and changed the your operator to be a Modal operator ,also added how to pas the button name to the operator , but the problem is that i could not get the coordinates of the mouse in respect to the movie clip, so i have used the region where the movie is :

import bpy
from bpy.props import *

class AddMarker(bpy.types.Operator):
    bl_idname = "wm.addmarker"
    bl_label = "add markers with names"

    def __init__(self):
        print("Start")

    def __del__(self):
        print("End")

    x = bpy.props.IntProperty()
    y = bpy.props.IntProperty()
    name = bpy.props.StringProperty()

    def execute(self, context):
        #using 'region' in this calculation  is wrong
        self.x -=bpy.context.region.x
        self.y -=bpy.context.region.y
        x = self.x/bpy.context.region.width
        y = self.y/bpy.context.region.height
        #add marker at that position
        bpy.ops.clip.add_marker(location=(x, y))
        #rename this marker
        bpy.data.movieclips[0].tracking.tracks.active.name=self.name
        #bpy.context.scene.active_clip.tracking.tracks.active.name=self.name
        return {'FINISHED'}

    def modal(self, context, event):

        if event.type == 'LEFTMOUSE':  
            self.x = event.mouse_x
            self.y = event.mouse_y 
            self.execute(context)
            return {'FINISHED'}

        elif event.type in ('RIGHTMOUSE', 'ESC'):  
            return {'CANCELLED'}

        return {'RUNNING_MODAL'}

    def invoke(self, context, event):
        print(context.window_manager.modal_handler_add(self))
        return {'RUNNING_MODAL'}





class MARKERPANEL(bpy.types.Panel):
    bl_label = "Add markers"
    bl_space_type = "CLIP_EDITOR"
    bl_region_type = "TOOLS"
    bl_category = "MARKERPANEL"


    def draw(self, context):
        f = ['left','right','floor','corner']

        for line in f:        

            layout = self.layout
            row = layout.row()

            sc = context.space_data
            clip = context.space_data.clip
            row.operator("wm.addmarker", text=line).name = line

bpy.utils.register_class(AddMarker)
bpy.utils.unregister_class(AddMarker)       
bpy.utils.register_class(MARKERPANEL)
bpy.utils.unregister_class(MARKERPANEL)   
bpy.utils.register_module(__name__)
$\endgroup$
  • $\begingroup$ Thanks for the info and code. Realy helped me. I haven't figured out how to get the proper x,y positions of the mouse click. But for now I put the marker at a locked position and just drag it to the correct position. $\endgroup$ – knutsel Mar 3 '15 at 17:12
  • $\begingroup$ If someone else wants to use the code: put the rename part in a for-loop. Then multiple video-files can be loaded. "for clip in bpy.data.movieclips: clip.tracking.tracks.active.name=self.name" $\endgroup$ – knutsel Mar 3 '15 at 17:16

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.