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

Applying a paragraph style to text frames in document

Contributor ,
Feb 15, 2015 Feb 15, 2015

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!!

TOPICS
Scripting
625
Translate
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

Guide , Feb 15, 2015 Feb 15, 2015

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

Translate
Adobe
Guide ,
Feb 15, 2015 Feb 15, 2015

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

Translate
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
Contributor ,
Feb 15, 2015 Feb 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();

Translate
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
Contributor ,
Feb 16, 2015 Feb 16, 2015
LATEST

Thanks again for getting me on the right track. This seems to work for me.

var docRef = app.activeDocument;

var textRef = docRef.textFrames;

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

//in the dialog box make a custom option that will by pass the paragraph styles

paraStyle.characterColor = docRef.swatches[2];

for(var i=textRef.length-1; i >= 0; i--) {

  

  try {

  

   paraStyle.applyTo(textRef.paragraphs[0], true);

   textRef.createOutline()

  

}

catch (e) {

    textRef.remove()

    }

}

//worry about the color after the outines have been created. Then it will be a group item.

redraw();

In my template file I use for this I have it set up as a bunch of 1 line story connected text boxes so I only have 1 paragraph in each. Now with this script I can copy and paste an excel spreadsheet of names, and each name will be individually grouped and that will be super helpful.

Translate
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