### Mocha Python Package Methods Source: https://borisfx.com/documentation/mocha/5.5.2/python-guide Provides examples of core functions from the mocha Python package for interacting with the Mocha application. Includes functions to get the executable directory and run the application with specified arguments. ```python # Return the absolute path of the mocha bin directory. mocha.get_mocha_exec_dir() #Run mocha application with given command-line arguments mocha.run_mocha(app='mochapro', footage_path='/tmp/myfootagepath.png', '--frame-rate 24 --in 0 --out 100') # override settings for offscreen buffers using mocha.Settings overridden_settings = mocha.Settings(override=True, read_overridden=True) overridden_settings.disable_offscreen_buffers = not overridden_settings.disable_offscreen_buffers ``` -------------------------------- ### Install Mocha Module to Python Source: https://borisfx.com/documentation/mocha/5.5.2/python-guide Installs the mocha Python module into your existing Python installation. This involves navigating to the mocha installation directory and running the setup.py script. ```shell C:\\Program Files\\mocha Pro V5\\python\\python.exe setup.py install ``` -------------------------------- ### Mocha v5.5.2 Python Scripting Guide - Introduction Source: https://borisfx.com/documentation/mocha/5.5.2/python-guide Introduction to the Mocha v5.5.2 Python scripting guide, assuming basic Python knowledge and highlighting the mocha Pro Python package. ```APIDOC ## Mocha v5.5.2 Python Scripting Guide ### Introduction Welcome to the **Mocha v5.5.2** Python scripting guide. This guide covers Python functions for Mocha v5.5.2 and assumes a basic understanding of Python coding. Examples primarily use the **mocha Pro** Python package, which generally apply to **mocha VR** as well. ``` -------------------------------- ### Obtain and Set Current Clip Source: https://borisfx.com/documentation/mocha/12.0.0/python-guide Code examples for getting the name of the default trackable clip and setting the currently displayed clip on the canvas. ```python from mocha.project import get_current_project #Get the clip you created the project with name = get_current_project().default_trackable_clip.name print('Default trackable clip name is', name) ``` ```python from mocha.project import get_current_project from mocha.ui import set_displayed_clip default_clip = get_current_project().default_trackable_clip #Set the clip currently showing on canvas to the default clip set_displayed_clip(default_clip) ``` -------------------------------- ### Create and Save Mocha Project with Python Source: https://borisfx.com/documentation/mocha/5.5.2/python-guide Demonstrates how to initialize a new Mocha project using the Python API. This involves importing necessary classes, creating Clip and Project objects, and saving the project to a file. It assumes the availability of `mocha.project`, `QCoreApplication`, and `sys` modules. ```python from mocha.project import Project, Clip from PySide6.QtCore import QCoreApplication import sys app = QCoreApplication(sys.argv) # Create a new Clip object (path to footage, optional clip name) clip = Clip('/path/myfile.exr', 'NewClip') # Create a new Project object with the clip proj = Project(clip) # Save the project to a file proj.save_as('/path/to/filename.mocha') # Save changes to the existing project file proj.save() ``` -------------------------------- ### Get Current Clip Information (Python) Source: https://borisfx.com/documentation/mocha/5.5.2/python-guide Provides Python examples for retrieving the default trackable clip and the clip currently displayed on the canvas using functions from the mocha library. ```python from mocha.project import get_current_project #Get the clip you created the project with name = get_current_project().default_trackable_clip.name print 'Default trackable clip name is', name from mocha.ui import get_displayed_clip #Get the clip currently showing on canvas name = get_displayed_clip().name print 'Currently displayed clip on canvas is', name ``` -------------------------------- ### Timeline Playhead Control Source: https://borisfx.com/documentation/mocha/8.0.0/python-guide This section covers the module-level functions for getting and setting the current frame (playhead position) in Mocha Pro, with examples for retrieving frame data and advancing the playhead. ```APIDOC ## Timeline Playhead Functions ### Description Provides functions to get and set the current frame (playhead position) of the project timeline. All frame indices are zero-indexed. ### Method GET / SET (Module-level functions) ### Endpoint `mocha.ui.get_current_frame()` `mocha.ui.set_current_frame(frame_index)` ### Parameters #### Path Parameters None #### Query Parameters None #### Request Body - **frame_index** (Integer) - Required (for `set_current_frame`) - The zero-indexed frame to set the playhead to. ### Request Example (Get Current Frame and Layer Data) ```python from mocha.ui import get_current_frame proj = get_current_project() current_layer = proj.layers[0] current_playhead_time = get_current_frame() frame_data = [] for contour in current_layer.contours: for point in contour.control_points: cp = point.get_point_data(current_playhead_time) frame_data.append(cp) print(frame_data) ``` ### Request Example (Advance Playhead) ```python from mocha.ui import get_current_frame, set_current_frame frame_set = set_current_frame(get_current_frame() + 5) ``` ### Response #### Success Response (200) - `get_current_frame()`: Returns the current frame index as an Integer. - `set_current_frame()`: Returns the new current frame index as an Integer or a success status. #### Response Example (For `get_current_frame()`): `10` (For `set_current_frame()`): `15` ``` -------------------------------- ### Create and Initialize a New Project Source: https://borisfx.com/documentation/mocha/12.5.0/python-guide Imports necessary classes and initializes a new project. It requires a QCoreApplication for external scripts and creates a Clip object, which is then used to instantiate a Project. The clip is deep-copied into the project. ```python from mocha.project import Project, Clip from PySide2.QtCore import QCoreApplication import sys # Ensure QCoreApplication is initialized for external scripts if not QCoreApplication.instance(): app = QCoreApplication(sys.argv) clip = Clip('/path/myfile.exr', 'NewClip') # The Clip name is optional proj = Project(clip) ``` -------------------------------- ### Manual SynthEyes Plugin Installation for After Effects (macOS) Source: https://borisfx.com/documentation/syntheyes/SynthEyesUM_files/installation_for_after This snippet outlines the manual installation procedure for SynthEyes plugins into Adobe After Effects on a macOS system. It guides users on removing previous installations and copying the required .plugin files to the designated location. ```bash # 1. If you have plugins installed from a pre-Boris-FX version of SynthEyes, remove the following folder to avoid duplicate effects: # /Applications/Adobe After Effects 20yy/Plug-ins/Effects # 2. Create a new "Boris FX SynthEyes" folder: # /Library/Application Support/Adobe/Common/Plug- ins/7.0/MediaCore/Boris FX SynthEyes # 3. Copy SyAFXAdvLens.plugin, SyAFXLens.plugin, and SyAFXMapper.plugin into the new Boris FX SynthEyes folder. # 4. Restart After Effects if it is already running. ``` -------------------------------- ### Example: Initializing Project on Tool Activation Source: https://borisfx.com/documentation/mocha/6.0.0/python-guide This function shows how to utilize the `on_activate` event handler to grab the current project when a tool becomes active. This is useful for setting up tool-specific data or state. ```python def on_activate(self): self.proj = get_current_project() ``` -------------------------------- ### Python: Initialize QCoreApplication Source: https://borisfx.com/documentation/mocha/5.6.0/python-guide Initializes a QCoreApplication object, which is required to connect to the mocha MediaIOServer. This enables reading QuickTime-associated media. ```python import sys from PySide2.QtCore import QCoreApplication app = QCoreApplication(sys.argv) ``` -------------------------------- ### Mocha Python API Methods Source: https://borisfx.com/documentation/mocha/9.0.0/python-guide Provides examples of core Python methods within the Mocha API for interacting with the Mocha application externally. These include functions to get the executable directory and to run the Mocha application with various command-line arguments. ```python import mocha # Return the absolute path of the mocha bin directory. mocha.get_mocha_exec_dir() # Run Mocha application with given command-line arguments mocha.run_mocha(app='mochapro', footage_path='/tmp/myfootagepath.png', frame_rate=24, in_point=0, out_point= 100) # override settings for offscreen buffers using mocha.Settings overridden_settings = mocha.Settings(override=True, read_overridden=True) overridden_settings.disable_offscreen_buffers = not overridden_settings.disable_offscreen_buffers # Run Mocha application with given project file mocha.run_mocha(app='mochapro', footage_path='/tmp/my_project.mocha') ``` -------------------------------- ### Create and Initialize a New Mocha Project Source: https://borisfx.com/documentation/mocha/8.0.0/python-guide Imports necessary classes (Project, Clip) and initializes a QCoreApplication if running externally. It then creates a Clip object with a specified path and name, and uses this clip to instantiate a new Project. The project is then saved to a .mocha file. ```python from mocha.project import Project, Clip from PySide2.QtCore import QCoreApplication import sys # Initialize QCoreApplication if running externally if not QCoreApplication.instance(): app = QCoreApplication(sys.argv) clip = Clip('/path/myfile.exr', 'NewClip') # Clip name is optional proj = Project(clip) proj.save_as('/path/to/filename.mocha') ``` -------------------------------- ### Watch Render and Export Progress with Callbacks Source: https://borisfx.com/documentation/mocha/9.0.0/python-guide Monitors the progress of render and export operations in Mocha FX projects. This example demonstrates connecting callback functions to watcher events for started, progress, and finished states, providing visual feedback and messages. ```python from PySide2.QtCore import QCoreApplication import sys from mocha.project import * app = QCoreApplication(sys.argv) proj = Project('/_clips/Results/Fish_remove.mocha') rm = RenderRemoveOperation() layer = proj.find_layers('REMOVE FISHY')[0] def on_start_rendering(): sys.stdout.write('Rendering started.\nProgress:\n') sys.stdout.write('[ %s ]' % (' ' * 100)) def on_start_exporting(): print('Exporting started') def on_progress(progress): sys.stdout.write('\r') sys.stdout.write('[ %s%s ]' % ('#' * progress, ' ' * (100 - progress))) def on_message(message): print(message) def on_finish(): print() print('Rendering is finished') # Watch the remove and show a progress bar watcher = rm.progress_watcher watcher.started.connect(on_start_rendering) watcher.progress_status.connect(on_progress) watcher.finished.connect(on_finish) # Render the remove from frames 0-10 clip = proj.render(rm, 0, 10, [layer]) print('Exporting!') # Watch the exporter and print the saved files watcher = clip.progress_watcher watcher.started.connect(on_start_exporting) watcher.progress_message.connect(on_message) watcher.finished.connect(on_finish) # Export the clip to a png sequence clip.export(None, '/tmp/exported', '.png', 'prefix_', '_suffix', 0, 10, 0) ``` -------------------------------- ### Create New Project with a Clip Source: https://borisfx.com/documentation/mocha/12.0.0/python-guide Generates a new project instance, optionally with an associated clip. If running externally, a QCoreApplication must be initialized first to enable connection to the Mocha MediaIOServer for reading media. A Clip object is created with a file path and an optional name, then passed to the Project constructor. ```python from mocha.project import Project, Clip from PySide2.QtCore import QCoreApplication import sys # Initialize QCoreApplication if running externally app = QCoreApplication(sys.argv) clip = Clip('/path/myfile.exr', 'NewClip') # The Clip name is optional proj = Project(clip) ``` -------------------------------- ### ParameterSet Initialization and Access Source: https://borisfx.com/documentation/mocha/12.5.0/python-guide Shows how to initialize and use the `ParameterSet` class for accessing parameters. It demonstrates creating a root `ParameterSet`, comparing it with nested access, and verifying that different methods of specifying nested parameters yield the same `ParameterSet` instance. ```python ps = proj.parameter_set() # the root parameter set. print(ps == ps[[]]) # should be True # Accessing nested parameters using tuples or chained calls print(ps['Layer_1', 'Layer_1_-_Spline_4', 'Layer_1_-_Spline_4_-_Control_Point_20'] == ps['Layer_1']['Layer_1_-_Spline_4']['Layer_1_-_Spline_4_-_Control_Point_20']) # should be True control_point_ps = ps['Layer_1', 'Layer_1_-_Spline_4', 'Layer_1_-_Spline_4_-_Control_Point_20'] print(control_point_ps == proj.parameter_set(['Layer_1', 'Layer_1_-_Spline_4', 'Layer_1_-_Spline_4_-_Control_Point_20'])) # should be True print(control_point_ps == proj.find_layers(Layer_1)[0].contours[0].control_points[0].parameter_set()) # should be True ``` -------------------------------- ### Control Mocha Playhead with Python Source: https://borisfx.com/documentation/mocha/5.5.2/python-guide Explains how to get and set the current frame (playhead position) in Mocha using the Python API. It provides examples of retrieving the current frame, setting it to a specific value, and performing calculations to move the playhead. This is useful for scripting frame-based operations. ```python from mocha.ui import get_current_frame, set_current_frame # Get the current frame index (zero-indexed) current_playhead_time = get_current_frame() # Example: Get control point data for a layer at the current frame # proj = get_current_project() # Assuming proj is already defined # current_layer = proj.layers[0] # frame_data = [] # for contour in current_layer.contours: # for point in contour.control_points: # cp = point.get_point_data(current_playhead_time) # frame_data.append(cp) # print frame_data # Set the playhead forward by 5 frames set_current_frame(get_current_frame() + 5) ``` -------------------------------- ### Import Mocha Module in Python Source: https://borisfx.com/documentation/mocha/5.5.2/python-guide Demonstrates how to import the mocha module into a separate Python installation after it has been successfully installed. ```python from mocha.project import * ```