Advertisement
Guest User

Untitled

a guest
Mar 3rd, 2015
192
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 3.42 KB | None | 0 0
  1. from __future__ import print_function
  2. import bpy
  3. import os
  4. class addmarkers(bpy.types.Operator):
  5. """ This operator adds markers
  6. add marker and give it a good name
  7. """
  8. bl_idname = "wm.addmarkers"
  9. bl_label = "addmarkers"
  10.  
  11. def execute(self, context):
  12. # lmc to add a marker and change the name of the track
  13.  
  14. bl_space_type='CLIP_EDITOR'
  15.  
  16. sc=context.space_data
  17. clip=sc.clip
  18. bpy.ops.clip.add_marker_at_click('INVOKE_DEFAULT') #click to add a marker
  19.  
  20.  
  21.  
  22. #bpy.data.movieclips["test.avi"].tracking.tracks["Track"].name="TESTNAME"
  23. #previous line is executed before add_marker_at_click is finished, so it doesn't work
  24. return {'FINISHED'}
  25.  
  26. def invoke(self, context, event):
  27. return self.execute(context)
  28.  
  29.  
  30.  
  31. class MARKERPANEL(bpy.types.Panel):
  32. bl_label = "Add markers"
  33. bl_space_type = "CLIP_EDITOR"
  34. bl_region_type = "TOOLS"
  35. bl_category = "MARKERPANEL"
  36.  
  37.  
  38. def draw(self, context):
  39. f = open('settings.txt', 'rt')
  40.  
  41. for line in f:
  42.  
  43. layout = self.layout
  44. row = layout.row()
  45.  
  46. sc = context.space_data
  47. clip = context.space_data.clip
  48. row.operator("wm.addmarkers", text=line)
  49.  
  50. bpy.utils.register_class(addmarkers)
  51. bpy.utils.unregister_class(addmarkers)
  52. bpy.utils.register_class(MARKERPANEL)
  53. bpy.utils.unregister_class(MARKERPANEL)
  54. bpy.utils.register_module(__name__)
  55.  
  56. import bpy
  57. from bpy.props import *
  58.  
  59. class AddMarker(bpy.types.Operator):
  60. bl_idname = "wm.addmarker"
  61. bl_label = "add markers with names"
  62.  
  63. def __init__(self):
  64. print("Start")
  65.  
  66. def __del__(self):
  67. print("End")
  68.  
  69. x = bpy.props.IntProperty()
  70. y = bpy.props.IntProperty()
  71. name = bpy.props.StringProperty()
  72.  
  73. def execute(self, context):
  74. #using 'region' in this calculation is wrong
  75. self.x -=bpy.context.region.x
  76. self.y -=bpy.context.region.y
  77. x = self.x/bpy.context.region.width
  78. y = self.y/bpy.context.region.height
  79. #add marker at that position
  80. bpy.ops.clip.add_marker(location=(x, y))
  81. #rename this marker
  82. bpy.data.movieclips[0].tracking.tracks.active.name=self.name
  83. #bpy.context.scene.active_clip.tracking.tracks.active.name=self.name
  84. return {'FINISHED'}
  85.  
  86. def modal(self, context, event):
  87.  
  88. if event.type == 'LEFTMOUSE':
  89. self.x = event.mouse_x
  90. self.y = event.mouse_y
  91. self.execute(context)
  92. return {'FINISHED'}
  93.  
  94. elif event.type in ('RIGHTMOUSE', 'ESC'):
  95. return {'CANCELLED'}
  96.  
  97. return {'RUNNING_MODAL'}
  98.  
  99. def invoke(self, context, event):
  100. print(context.window_manager.modal_handler_add(self))
  101. return {'RUNNING_MODAL'}
  102.  
  103.  
  104.  
  105.  
  106.  
  107. class MARKERPANEL(bpy.types.Panel):
  108. bl_label = "Add markers"
  109. bl_space_type = "CLIP_EDITOR"
  110. bl_region_type = "TOOLS"
  111. bl_category = "MARKERPANEL"
  112.  
  113.  
  114. def draw(self, context):
  115. f = ['left','right','floor','corner']
  116.  
  117. for line in f:
  118.  
  119. layout = self.layout
  120. row = layout.row()
  121.  
  122. sc = context.space_data
  123. clip = context.space_data.clip
  124. row.operator("wm.addmarker", text=line).name = line
  125.  
  126. bpy.utils.register_class(AddMarker)
  127. bpy.utils.unregister_class(AddMarker)
  128. bpy.utils.register_class(MARKERPANEL)
  129. bpy.utils.unregister_class(MARKERPANEL)
  130. bpy.utils.register_module(__name__)
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement