• Global community
    • Language:
      • Deutsch
      • English
      • Español
      • Français
      • Português
  • 日本語コミュニティ
    Dedicated community for Japanese speakers
  • 한국 커뮤니티
    Dedicated community for Korean speakers
Exit
0

Premiere Pro ExtendScript changing the text of a MOGRT

New Here ,
Aug 07, 2024 Aug 07, 2024

Copy link to clipboard

Copied

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!

TOPICS
SDK

Views

200

Translate

Translate

Report

Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines

correct answers 1 Correct answer

Community Beginner , Aug 07, 2024 Aug 07, 2024

Hi,
I use extendscript to insert my text in to mogrt template and this works fine.

I use follow script (simplified):

 

var component = clip.getMGTComponent()

var titleParam = component.properties.getParamForDisplayName('title')
var params = JSON.parse(titleParam.getValue())
params.textEditValue = object.title
params.fontTextRunLength = [object.title.length]
titleParam.setValue(JSON.stringify(params), true)

 

When you getting value you must parse json, then set textEditValue = your text.

Important part

...

Votes

Translate

Translate
Adobe Employee ,
Aug 07, 2024 Aug 07, 2024

Copy link to clipboard

Copied

Was your .mogrt created in After Effects? The API is designed for AE-created .mogrts.

Votes

Translate

Translate

Report

Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
New Here ,
Aug 07, 2024 Aug 07, 2024

Copy link to clipboard

Copied

Thank you for the quick reply.  

How can I tell?  I did not create it?  

I did try one of the MOGRTs that you can edit directly on the preview after dropping it in and another type where you have to go to "Edit" once selected in Essential Graphics and then edit the text there.  I figured that was probably each type and was trying to test both.

The one referenced above is the type where you can click on it in the preview video and edit it directly from there.  That is the only type I could get to list out componentsParam at all.  The other typpe, where you click on edit in Essential Graphics, has Opacity, Montion, and Capsule components but none that seem like they would have editable text.

For what it is worth, being able to programatically just add text would be enough for my purposes.  I couldn't figure out how to do that so now I am going down the path of adding a MOGRT (which I can do) but I then can't set the text for it.

Votes

Translate

Translate

Report

Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Community Beginner ,
Aug 07, 2024 Aug 07, 2024

Copy link to clipboard

Copied

Hi,
I use extendscript to insert my text in to mogrt template and this works fine.

I use follow script (simplified):

 

var component = clip.getMGTComponent()

var titleParam = component.properties.getParamForDisplayName('title')
var params = JSON.parse(titleParam.getValue())
params.textEditValue = object.title
params.fontTextRunLength = [object.title.length]
titleParam.setValue(JSON.stringify(params), true)

 

When you getting value you must parse json, then set textEditValue = your text.

Important part - you must set fontTextRunLength = length of your inserted string.

And you must include json parser of course 😃 (https://gist.github.com/atheken/654510)

Sorry for my English, its not my primary language.

I hope this code will help you.

Votes

Translate

Translate

Report

Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
New Here ,
Aug 08, 2024 Aug 08, 2024

Copy link to clipboard

Copied

Thank you for the response.  I think that is exactly what I need.

I've been trying and so far I can't get it to work. Is there an easy way to tell if it is a .mogrt that was created in after effects and therefore supported with extendscript?  That might help me narrow down my issues.  If there is a basic lower third .mogrt that comes with Premiere Pro or is freely available known to work (created in After Effects), that would be even better.

I noticed that you were using clip.getMGTComponent() without any parameters.  Is that how you are adding it to your timeline?  I was using activeSeq.importMGT(mogrtPath, targetTime.ticks, trackIndex, 0);  I'm not sure which one I should be using.

 

 

Votes

Translate

Translate

Report

Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
New Here ,
Aug 08, 2024 Aug 08, 2024

Copy link to clipboard

Copied

LATEST

I got it to work!

My problem was in fact that I was trying to use the wrong kind of .mogrt.  I actually had gotten further with some code that was going the wrong way after the text inside the wrong kind of .mogrt.  I took a fresh approach with code like in your example and got it to work.

Thank you both for the help!

Votes

Translate

Translate

Report

Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines