Skip to content

feat: Backlog/framework loader premiere #555

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Open
wants to merge 6 commits into
base: backlog/framework-loader
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -33,6 +33,7 @@ window.FTRACK_RPC_FUNCTION_MAPPING = {
saveProjectAs:"saveProjectAs",
render:"render",
openProject:"openProject",
loadAsset:"loadAsset",
};

window.ftrackInitialiseExtension = function(session, event_manager, remote_integration_session_id) {
Expand Down
104 changes: 85 additions & 19 deletions projects/framework-premiere/extensions/js/pp.jsx
Original file line number Diff line number Diff line change
Expand Up @@ -32,10 +32,10 @@ function hasProject() {
return app.project?"true":"false";
}

/*
* Returns the path of the document, or an empty string if it has not been saved
*/
function getProjectPath() {
/*
* Returns the path of the document, or an empty string if it has not been saved
*/
try {
return exportPath(app.project.path);
} catch (e) {
Expand All @@ -44,12 +44,12 @@ function getProjectPath() {
}
}

/*
* Save the current project
*
* Note: Can't check if document is saved in premiere
*/
function saveProject() {
/*
* Save the current project
*
* Note: Can't check if document is saved in premiere
*/
try {
app.project.save();
return "true";
Expand All @@ -59,11 +59,11 @@ function saveProject() {
}
}

/*
* Saves the project to the given temp_path, return "true" if successful,
* "false" otherwise. Support psd or psb format.
*/
function saveProjectAs(temp_path) {
/*
* Saves the project to the given temp_path, return "true" if successful,
* "false" otherwise. Support psd or psb format.
*/
try {
app.project.saveAs(importPath(temp_path));
return "true";
Expand All @@ -75,10 +75,10 @@ function saveProjectAs(temp_path) {

// Render

/*
* Render the current active sequence to the given output_path using the given preset
*/
function render(output_path, preset_path) {
/*
* Render
*/
try {
app.enableQE();
var seq = app.project.activeSequence;
Expand All @@ -97,11 +97,11 @@ function render(output_path, preset_path) {
}


/*
* Opens the project from the given path, return "true" if successful,
* "false" otherwise.
*/
function openProject(path) {
/*
* Opens the project from the given path, return "true" if successful,
* "false" otherwise.
*/
try {
app.openDocument(path);
return "true";
Expand All @@ -111,3 +111,69 @@ function openProject(path) {
}
}

/**
* Create bins in root based on treepath provided on the form 'ftrack/entity1/entity2...'
*/
function createBins(treepath) {
var root = app.project.rootItem;
var result = root;
var folders = treepath.split("/");
for (var i=0; i<folders.length; i++) {
var folder = null;
for (var j=0; j<result.children.length; j++) {
if (result.children[j].name == folders[i]) {
folder = result.children[j];
break;
}
}
if (!folder) {
folder = result.createBin(folders[i]);
}
result = folder;
}
return result;
}

/*
* Loads the file asset into the current project at the given tree path (created if not exists).
*/
function loadAsset(path, treepath, members) {
if (hasProject() == "false") {
alert("No project open, can't load image");
return "false";
}
try {
var root = app.project.rootItem;
// Expect treepath to be in the form "folder1/folder2/folder3", create folders if not exists
var parent = root;
if (treepath && treepath !== "") {
parent = createBins(treepath);
}
if (members && members.length > 0) {
// Dealing with a image sequence, expand it
var files = [];
var sequence_folder = importPath(path);
var member_list = members.split(",");
for (var i=0; i<member_list.length; i++) {
files.push(sequence_folder+"/"+member_list[i]);
}
if (app.project.importFiles(files, false, parent, true)) {
return "true";
} else {
alert("Failed to import sequence files: "+path+"["+member_list+"] to "+treepath);
return "false";
}
} else {
var files = [importPath(path)];
if (app.project.importFiles(files, false, parent, false)) {
return "true";
} else {
alert("Failed to import single file: "+path+" to "+treepath);
return "false";
}
}
} catch (e) {
alert(e);
return "false";
}
};
Original file line number Diff line number Diff line change
@@ -0,0 +1,66 @@
# :coding: utf-8
# :copyright: Copyright (c) 2024 ftrack
import os

from ftrack_framework_core.plugin import BasePlugin
from ftrack_framework_core.exceptions.plugin import PluginExecutionError

from ftrack_utils.paths import check_image_sequence
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Use clique instead

from ftrack_utils.string import str_context
from ftrack_utils.rpc import JavascriptRPC


class PremiereImageLoaderPlugin(BasePlugin):
name = 'premiere_image_loader'

def run(self, store):
'''
Expects the path to image to load in *store*, loads the image in Premiere
through RCP call.
'''

image_path = store.get('component_path')
if not image_path:
raise PluginExecutionError(f'No image path provided in store!')

try:
# Get existing RPC connection instance
premiere_connection = JavascriptRPC.instance()

component = self.session.query(
f"Component where id={store['entity_id']}"
).first()
context_path = (
f"ftrack/{str_context(component['version']['asset'])}/"
f"v{component['version']['version']:03}"
)
if store.get('is_sequence'):
# Compile members
sequence_metadata = check_image_sequence(
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Use clique instead

image_path, with_members=True
)
sequence_folder = os.path.dirname(image_path)
load_result = premiere_connection.rpc(
'loadAsset',
[
sequence_folder.replace('\\', '/'),
context_path,
','.join(sequence_metadata['members']),
],
)
else:
load_result = premiere_connection.rpc(
'loadAsset',
[image_path.replace('\\', '/'), context_path, ''],
)

if not load_result:
raise PluginExecutionError(
f'Failed to load image in Premiere!'
)

except Exception as e:
self.logger.exception(e)
raise PluginExecutionError(f'Exception loading the image: {e}')

store['load_result'] = load_result
11 changes: 11 additions & 0 deletions projects/framework-premiere/extensions/premiere.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -15,3 +15,14 @@ tools:
options:
tool_configs:
- premiere-project-opener
- name: load
action: true
menu: false # True by default
label: "Loader"
dialog_name: framework_standard_loader_dialog
options:
tool_configs:
- premiere-image-loader
- premiere-movie-loader
- premiere-sequence-loader
docked: false
Original file line number Diff line number Diff line change
@@ -0,0 +1,30 @@
type: tool_config
name: premiere-image-loader
config_type: loader
compatible:
entity_types:
- FileComponent
supported_file_extensions:
- ".bmp"
- ".gif"
- ".jpg"
- ".jpeg"
- ".psd"
- ".png"
- ".tiff"
- ".tif"
- ".tga"


engine:
- type: plugin
tags:
- context
plugin: resolve_entity_path
ui: show_component

- type: plugin
tags:
- loader
plugin: premiere_image_loader

Original file line number Diff line number Diff line change
@@ -0,0 +1,27 @@
type: tool_config
name: premiere-movie-loader
config_type: loader
compatible:
entity_types:
- FileComponent
supported_file_extensions:
- ".avi"
- ".mp4"
- ".m4v"
- ".mov"
- ".mpg"
- ".mpeg"
- ".wmv"

engine:
- type: plugin
tags:
- context
plugin: resolve_entity_path
ui: show_component

- type: plugin
tags:
- loader
plugin: premiere_image_loader

Original file line number Diff line number Diff line change
@@ -0,0 +1,30 @@
type: tool_config
name: premiere-sequence-loader
config_type: loader
compatible:
entity_types:
- SequenceComponent
supported_file_extensions:
- ".bmp"
- ".gif"
- ".jpg"
- ".jpeg"
- ".psd"
- ".png"
- ".tiff"
- ".tif"
- ".tga"


engine:
- type: plugin
tags:
- context
plugin: resolve_entity_path
ui: show_component

- type: plugin
tags:
- loader
plugin: premiere_image_loader

2 changes: 1 addition & 1 deletion projects/framework-premiere/pyproject.toml
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
[tool.poetry]
name = "ftrack-framework-premiere"
version = "24.6.0"
version = "24.7.0rc1"
description='ftrack Premiere integration'
authors = ["ftrack Integrations Team <[email protected]>"]
readme = "README.md"
Expand Down
1 change: 1 addition & 0 deletions projects/framework-premiere/release_notes.md
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@

## upcoming

* [new] Studio asset load capability, covering single file images, movies and image sequences.
* [changed] Host, Client instance; Pass run_in_main_thread argument.
* [fix] Init; Fix on_run_tool_callback options argument.

Expand Down
Loading
Loading