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

Reset Paragraph through scripting

Explorer ,
Oct 11, 2023 Oct 11, 2023

Copy link to clipboard

Copied

Hi,

How can I use Reset Paragraph option from Paragraph panel through scripting?

 

I have this simple code:

function resetParagraphStylesInProject() {
    var project = app.project;

        for (var i = 1; i <= project.numItems; i++) {
            var item = project.item(i);

            if (item instanceof CompItem) {

                for (var j = 1; j <= item.numLayers; j++) {
                    var layer = item.layer(j);

                    if (layer instanceof TextLayer) {
                        layer.property("Source Text").value.resetParagraphStyle();
                    }
                }
            }
        }
}


resetParagraphStylesInProject();

But this does nothing for me. Or, atleast it does not do the same thing as when I click Reset Paragraph manually. Is something wrong in my code? Are "Reset Paragraph" and "resetParagraphStyle()" different things?

My problem is I have big projects with lot of Hindi/Arabic texts which are occasionally displayed incorrectly. Hitting "Reset Paragraph" fixes this issue. But I would like to fix this automatically with script but I am not sure what is wrong here.

I attached a simple aep test file with one text layer which displays the the inccorectly like this 

wrong.png 

After Reset Paragraph it should look like this: 

after.png

Thanks in advance,

Martin

TOPICS
Error or problem , How to , Scripting

Views

349

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 Expert , Oct 11, 2023 Oct 11, 2023

Try replacing this line:

layer.property("Source Text").value.resetParagraphStyle();

with this:

var textDoc = layer.property("Source Text").value;
textDoc.resetParagraphStyle();
layer.property("Source Text").setValue(textDoc);

 

 

Votes

Translate

Translate
Community Expert ,
Oct 11, 2023 Oct 11, 2023

Copy link to clipboard

Copied

Try replacing this line:

layer.property("Source Text").value.resetParagraphStyle();

with this:

var textDoc = layer.property("Source Text").value;
textDoc.resetParagraphStyle();
layer.property("Source Text").setValue(textDoc);

 

 

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
Explorer ,
Oct 12, 2023 Oct 12, 2023

Copy link to clipboard

Copied

Hi Dan,

 

Thank you for you reply. This is almost there. Your suggestion works for the example I have provided. However where this approach fails is when the text layer has multiple styles in it. For example if part of the text is different color, or bold. Manually hitting Reset Paragraph will keep all the different styles intact. This approach will disregard the multiple styles and everything will be the same style based on the first character.

 

Do you know a workaround which could help me keep different styles in one layer?

 

I also tried looking into the new textDocument.composerEngine in 2024 version with hopes this could help, but sadly it looks its read-only.

 

Thank 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
Community Expert ,
Oct 12, 2023 Oct 12, 2023

Copy link to clipboard

Copied

Unfortunately, when a script touches the text document, you lose the multiple styles. I thought maybe using app.executeCommand(app.findMenuCommandId("Reset Paragraph")) would work, but it doesn't appear to. So, I'm out of ideas. Sorry.

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
Explorer ,
Oct 12, 2023 Oct 12, 2023

Copy link to clipboard

Copied

Thank you Dan once again. I will have to make it work with your previous suggestion.

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
Adobe Employee ,
Nov 20, 2023 Nov 20, 2023

Copy link to clipboard

Copied

LATEST

Per-character scripting control is now available in Beta.

 

https://community.adobe.com/t5/after-effects-beta-discussions/per-character-scripting-public-beta-an...

 

One of the specific improvements is that round tripping a Text Layer through a TextDocument instance will no longer lose individual styling.

 

Douglas Waterfall

After Effects Engineering

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