I am attempting to programmatically use motion tracking in Blender. My script successfully adds the image strip to a clip editor but not the one in the motion tracking workspace.
bpy.ops.workspace.append_activate(idname="Motion Tracking")
bpy.context.area.type = 'CLIP_EDITOR'
Making the context a clip editor using the code above only makes the local area within the scripting workspace become a clip editor, so when I switch to motion tracking that workspace is still empty. I used a similar sequence of commands to activate and add to the sequence editor in the VSE but it does not seem to work with motion tracking. Does anyone have any suggestions or is this possibly a bug that I will have to manually workaround?
UPDATE 1
Thanks to some help from another user, I was able to change the workspace to motion tracking but I do not think it is active as the clip editor in that workspace is not used. Instead, it changes the text editor area in the scripting workspace. Here is my code with some comments to hopefully clarify my issue.
import bpy
# ImportHelper is a helper class, defines filename and
# invoke() function which calls the file selector.
from bpy.props import StringProperty, CollectionProperty
from bpy.types import Operator
from bpy_extras.io_utils import ImportHelper
from pathlib import Path
from bpy import data as D
class Motion_OT_Tracking(Operator, ImportHelper):
"""Imports rendered images and tracks cells"""
bl_idname = "import_rendered.images" # important since its how bpy.ops.import_test.some_data is constructed
bl_label = "Import Images"
bl_options = {"REGISTER", "UNDO"}
directory: StringProperty(
options={'HIDDEN'}
)
files: CollectionProperty(type=bpy.types.PropertyGroup)
# ImportHelper mixin class uses this
filename_ext = bpy.path.extensions_image
# List of operator properties, the attributes will be assigned
# to the class instance from the operator settings before calling.
@classmethod
def poll(cls, context):
return True
##use filename_ext to verify correct file type (acceptable image) how??
def execute(self, context):
for ws in D.workspaces: ##changes workspace to motion tracking
if ws.name == "Motion Tracking":
bpy.context.window.workspace = ws
# bpy.ops.workspace.append_activate(idname="Motion Tracking") ##not sure if i need this somewhere
bpy.context.area.type = 'CLIP_EDITOR'
directory_path = Path(self.filepath).parent
file_list = []
for file in self.files: #creates list of file names selected from file selector po up
file_list.append({"name":file.name})
bpy.ops.clip.open( ##adds files to clip editor
directory=str(directory_path),
files=file_list,
relative_path=True
)
bpy.context.area.type = 'TEXT_EDITOR'
return {'FINISHED'}
def invoke(self, context, event):
context.window_manager.fileselect_add(self)
return {'RUNNING_MODAL'}
def register():
bpy.utils.register_class(Motion_OT_Tracking)
def unregister():
bpy.utils.unregister_class(Motion_OT_Tracking)
if __name__ == "__main__":
register()
# test call
bpy.ops.import_rendered.images('INVOKE_DEFAULT')
Any help is greatly appreciated, thank you!