Skip to main content
Inspiring
October 11, 2023
Answered

Reset Paragraph through scripting

  • October 11, 2023
  • 1 reply
  • 915 views

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 

 

After Reset Paragraph it should look like this: 

Thanks in advance,

Martin

This topic has been closed for replies.
Correct answer Dan Ebberts

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

 

 

1 reply

Dan Ebberts
Community Expert
Dan EbbertsCommunity ExpertCorrect answer
Community Expert
October 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);

 

 

Inspiring
October 12, 2023

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

Dan Ebberts
Community Expert
Community Expert
October 12, 2023

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.