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
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);
}
}