Skip to main content
Known Participant
February 15, 2015
Answered

Applying a paragraph style to text frames in document

  • February 15, 2015
  • 1 reply
  • 646 views

Hello everyone! Not sure what I am doing wrong here, and I am having trouble finding examples of this online, so I thought I would ask.

var docRef = app.activeDocument;

var textRef = docRef.textFrames;

var paraStyle = docRef.paragraphStyles.getByName ("LeftIndent");

var iCount = textRef.paragraphs.length; //This is the error that shows up.

for(var i=0; i<iCount; i++) {

paraStyle.applyTo(textRef.paragraphs, true);

}

redraw();

Thanks in advance!!

This topic has been closed for replies.
Correct answer Qwertyfly___

‌at a glance I would say you need to loop textframes and within that loop paragraphs.

1 reply

Qwertyfly___
Qwertyfly___Correct answer
Legend
February 15, 2015

‌at a glance I would say you need to loop textframes and within that loop paragraphs.

Known Participant
February 15, 2015

Thanks imagecollection, I almost have it figured out now. I still get an error every so often. I am just making random text boxes with random type in it, and sometimes I will get an error. I have no idea why the particular text box makes it have an error, when I delete it the error goes away, I am not doing anything different to it that I know of.

var docRef = app.activeDocument;

var textRef = docRef.textFrames;

var paraStyle = docRef.paragraphStyles.getByName ("LeftIndent");

for(var i=0; i<textRef.length; i++) {

   

    for(var j = 0; j < textRef.paragraphs.length; j++) {

   

    paraStyle.applyTo(textRef.paragraphs, true);   //Some of the time I get an error here when I make a text box it doesn't like?

    }

}

redraw();