Copy link to clipboard
Copied
I hope I'm wrong but I'm reading its not possible to programmatically replace an image in a mogrt (which if it's not seems weird when you can do so by drag and drop manually). If this is the case, is there a workaround? I read that there may be some way with a trackItem but didnlt really understand the approach. Perhaps there's a way with QE (I know this unsupported). Issue is that image replacement is at the core of quite a large project in which i need to swap out thousands of images within a mogrt. I do know the exact position and size of the images so perhaps i could just add them via my script? However, beacuse the wiggle effect is on the surrounding shape in which the images need to sit this will look a bit weird as the image would not track the movement. Any help hugely appreciated!!!
OK so this was my workaround which places an image into position on top of my mogrt creating more or less the same effect. Hope this helps as I've found it very difficult working this out. NT Productions youtube channel was useful in cracking this, particularly this video: https://www.youtube.com/watch?v=1yEiBQghhhA
// Include the JSON2 library
#include "json2.js"
// Function to read and parse JSON file
function readJSONFile(filePath) {
var file = new File(filePath);
file.open('r');
...
Copy link to clipboard
Copied
is it a ready mogrt template or you created it? in After Effects:
the image could be parented to the frame with wiggle expression applied,
and most importantly, if the expression is not universalized and you are on
a pc that uses another language than English, this could be the culprit.
Is the mogrt created with image placeholder considerations?
Can you give more details about the mogrt or share it privately?
Copy link to clipboard
Copied
Hey Carlos, many thanks for your reply. I'm on a macbook pro which uses English. The main goal here is to find some way of programmatically swapping out the placeholder image seen here programmatically once in premiere pro. NOt sure how to share as mogrt not supported for upload here, but more than happy to do so somehow... thanks again in advance!
Copy link to clipboard
Copied
Also, I tried logging the values and got this: MoGRT clip found on track 7. QE track item found. Logging all properties of the MoGRT track item: Property: quiz-question-image, Type: undefined, Value: 00000000-0000-0000-0000-000000000000 Property: tv-scalep, Type: undefined, Value: 0.046875,0.08333333333333 Property: tv-position, Type: undefined, Value: 0.26822916666667,0.54537037037037 Property: tv-opacity, Type: undefined, Value: 0
Copy link to clipboard
Copied
OK so this was my workaround which places an image into position on top of my mogrt creating more or less the same effect. Hope this helps as I've found it very difficult working this out. NT Productions youtube channel was useful in cracking this, particularly this video: https://www.youtube.com/watch?v=1yEiBQghhhA
// Include the JSON2 library
#include "json2.js"
// Function to read and parse JSON file
function readJSONFile(filePath) {
var file = new File(filePath);
file.open('r');
var content = file.read();
file.close();
return JSON.parse(content);
}
// Function to normalize position values based on sequence dimensions
function normalizePosition(x, y, seqWidth, seqHeight) {
return [x / seqWidth, y / seqHeight];
}
// Sample JSON content (replace this with your actual JSON content)
var jsonQuestionFilePath = "/Users/edwardnewton/Downloads/quiz-buddha/quiz-question1.json";
var jsonQuestionContent = readJSONFile(jsonQuestionFilePath);
var mogrtQuestionDetails = jsonQuestionContent.mogrts;
// Get the active sequence
var sequence = app.project.activeSequence;
// Get sequence dimensions
var seqWidth = sequence.frameSizeHorizontal;
var seqHeight = sequence.frameSizeVertical;
$.writeln("Sequence Dimensions: Width = " + seqWidth + ", Height = " + seqHeight);
// Test buddha-tv MoGRT insertion and image alignment
var buddhaTVDetails = mogrtQuestionDetails.filter(function(m) { return m.mogrtName === "buddha-tv"; })[0];
if (buddhaTVDetails) {
var buddhaTVTime = new Time();
buddhaTVTime.seconds = 10; // Set this to your desired start time for testing
// Add the MoGRT
sequence.importMGTFromLibrary(buddhaTVDetails.libraryName, buddhaTVDetails.mogrtName, buddhaTVTime.ticks, 7, -1);
// Now add the image on top of the MoGRT
var imageFilePath = "/Users/edwardnewton/Downloads/quiz-buddha/2024-06-13/1718299838885/questions/question1/questionImage.png"; // Set the correct path to your image
var imageStartTime = new Time();
imageStartTime.seconds = buddhaTVTime.seconds; // Start at the same time as the MoGRT
// Import the image
var importArray = [imageFilePath];
app.project.importFiles(importArray, true, app.project.rootItem, false);
// Adding a delay to ensure the image is imported
$.sleep(500); // 500 milliseconds delay
var imageProjectItem = app.project.rootItem.findItemsMatchingMediaPath(imageFilePath, true)[0];
if (imageProjectItem) {
sequence.videoTracks[8].insertClip(imageProjectItem, imageStartTime.ticks); // Assuming we want to place the image on V9
var imageClip = sequence.videoTracks[8].clips[sequence.videoTracks[8].clips.numItems - 1];
// Log clip details
$.writeln("Image clip details: " + JSON.stringify(imageClip));
// Find and log components and properties
var thisComponent, thisProp;
for(var c = 0; c < imageClip.components.numItems; c++) {
thisComponent = imageClip.components[c];
$.writeln("Component: " + thisComponent.displayName + ", Match Name: " + thisComponent.matchName);
// loop through the properties of each effect/component
for(var cc = 0; cc < thisComponent.properties.length; cc++) {
thisProp = thisComponent.properties[cc];
$.writeln("Property: " + thisProp.displayName + ", Value: " + thisProp.getValue());
}
}
// Set the position and scale of the image
var motionComponent;
for (var i = 0; i < imageClip.components.numItems; i++) {
var component = imageClip.components[i];
if (component.matchName === "AE.ADBE Motion") {
motionComponent = component;
break;
}
}
if (motionComponent) {
var positionProperty;
var scaleProperty;
for (var j = 0; j < motionComponent.properties.numItems; j++) {
var prop = motionComponent.properties[j];
if (prop.displayName === "Position") {
positionProperty = prop;
}
if (prop.displayName === "Scale") {
scaleProperty = prop;
}
}
if (positionProperty && scaleProperty) {
$.writeln("Motion Component found. Setting properties...");
// Normalize the position values
var normalizedPosition = normalizePosition(515.8, 589.6, seqWidth, seqHeight);
$.writeln("Setting Position to: " + JSON.stringify(normalizedPosition));
positionProperty.setValue(normalizedPosition, true); // Position
// Set the scale value
var scaleValue = 44.3;
$.writeln("Setting Scale to: " + scaleValue);
scaleProperty.setValue(scaleValue, true); // Scale
$.writeln("Image position and scale set.");
} else {
$.writeln("Failed to find Position and Scale properties for the image.");
}
} else {
$.writeln("Failed to find Motion component for the image.");
}
} else {
$.writeln("Failed to find image in project: " + imageFilePath);
}
}