Premiere Pro ExtendScript changing the text of a MOGRT
I'm trying to use extend script to add MOGRTs and set the text value for them. I am using VSCode and execurting the script directly with debugging. I'm able to automate the creation of my videos with the exception of this peice.
I am able to add the .mgrt and even iterate over the Components to find the Text Component and then go through its paramters to find the Source Text component. I tried using .setValue() but that just makes the text blank and changes the font. When I do .getValue() I get a weird character, so I think it is returning an object and not a string.
Here is the almost working code.
function importMoGRTAndInspectProperties(mogrtPath, trackIndex) {
var activeSeq = app.project.activeSequence;
if (activeSeq) {
var targetTime = activeSeq.getPlayerPosition();
var newTrackItem = activeSeq.importMGT(mogrtPath, targetTime.ticks, trackIndex, 0); // Set the video track index to V3 (trackIndex = 2)
if (newTrackItem) {
$.writeln("Successfully imported MoGRT: " + newTrackItem.name);
if (newTrackItem.components.length > 0) {
for (var i = 0; i < newTrackItem.components.length; i++) {
var component = newTrackItem.components[i];
$.writeln("Component " + i + ": " + component.matchName);
// Check if the component is the Text component
if (component.matchName === "AE.ADBE Text") {
var textComp = component;
var params = textComp.properties;
$.writeln("Parameters for Text Component:");
for (var z = 0; z < params.numItems; z++) {
var thisParam = params[z];
if (thisParam) {
$.writeln("Parameter " + (z + 1) + ": " + thisParam.displayName);
}
}
// Example: Set the "Source Text" parameter to a new value
var srcTextParam = params.getParamForDisplayName("Source Text");
if (srcTextParam) {
try {
var currentValue = srcTextParam.getValue();
$.writeln("Current Source Text value: " + currentValue);
//currentValue.text = "hello";
//srcTextParam.setValue(currentValue);
//$.writeln("Set Source Text parameter to: hello");
} catch (e) {
$.writeln("Error setting Source Text parameter: " + e.message);
}
} else {
$.writeln("Source Text parameter not found.");
}
}
}
} else {
$.writeln("No components found in the imported MoGRT.");
}
} else {
$.writeln("Unable to import specified .mogrt file.");
}
} else {
$.writeln("No active sequence.");
}
}
// Provide the path to your MoGRT file here
var mogrtPath = "/Users/<username>/Library/Application Support/Adobe/Common/Motion Graphics Templates/Titles/Bold Presents.mogrt"; // Update this path to your MoGRT file
importMoGRTAndInspectProperties(mogrtPath, 2); // Set to the third video track (V3)
Thank you in advance. I've been going in circles trying to solve this for hours!
