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
After Reset Paragraph it should look like this:
Thanks in advance,
Martin
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);
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);
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
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.
Copy link to clipboard
Copied
Thank you Dan once again. I will have to make it work with your previous suggestion.
Copy link to clipboard
Copied
Per-character scripting control is now available in Beta.
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