Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- 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__)
- 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__)
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement