# Adding tracks/markers with a custom name?

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
add marker and give it a good name
"""

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.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_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

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


for information: picture of the custom menu

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 *

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
#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):
return {'RUNNING_MODAL'}

class MARKERPANEL(bpy.types.Panel):
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