8 Replies Latest reply on Mar 5, 2008 7:00 AM by (Tim_Melis)

    [js] [cs2] Apply paragraph style

      Hi,

      I'm trying to automaticaly apply paragraph styles to every paragraph on every text frame, on every page.

      I would like to check some specific attributes of the first character of every paragraph and then choose the right style. Something like the code below...

      for (var j = app.activeDocument.stories.length - 1; j >= 0; j--) {

      for (var k = app.activeDocument.stories(j).paragraphs.count - 1; k >= 0; k--) {

      if (app.activeDocument.stories(j).paragraphs(k).characters(0).appliedFont == "Arial"){
      if (app.activeDocument.stories(j).paragraphs(k).characters(0).fontStyle == "Bold"){
      if (app.activeDocument.stories(j).paragraphs(k).characters(0).fillColor == "Black"){
      if (app.activeDocument.stories(j).paragraphs(k).characters(0).pointSize == 7){
      if (app.activeDocument.stories(j).paragraphs(k).leftIndent == 2){
      if (app.activeDocument.stories(j).paragraphs(k).firstLinetIndent == 1){
      app.activeDocument.stories(j).paragraphs(k).applyParagraphStyle("test",true);
      }
      }
      }
      }
      }
      }
      }

      }

      However, when running the script, an error was trown "object undefined"...

      How do I check if the text is aligned left, right or centered?

      Thanx for any help

      Tim
        • 1. Re: [js] [cs2] Apply paragraph style
          Peter Kahrel Adobe Community Professional & MVP
          For "firstLinetIndent", use "firstLineIndent". Doesn't look as if that answers your question, though.

          To check if the text is aligned left, right or centered, use justification (...paragraphs(k).justification).

          By the way, it's probably much quicker to do this with find/replace.

          Peter
          • 2. Re: [js] [cs2] Apply paragraph style
            Level 1
            Thanks Peter...

            Do you mean using something like this ...?

            app.findPreferences = app.changePreferences = null;
            app.findPreferences.appliedFont = 'Arial';
            app.changePreferences.appliedFont = 'Courier';
            app.activeDocument.search('',undefined,undefined,'');

            But how to replace it by a paragraph style ?

            Tim
            • 3. Re: [js] [cs2] Apply paragraph style
              Peter Kahrel Adobe Community Professional & MVP
              Just add a line
              >app.changePreferences.appliedParagraphStyle = "test";

              somewhere before the last line. That should do it, I think.

              Peter
              • 4. Re: [js] [cs2] Apply paragraph style
                Level 1
                Thanks Peter...

                Is there a property to remove or keep paragraph style exceptions ?

                Tim
                • 5. Re: [js] [cs2] Apply paragraph style
                  Level 1
                  Tim,

                  Do you have the Scripting Reference? Most of the answers to your questions are in there (although it's not the easiest of documents to find your way around if you're a newcomer).

                  When you use the search features from a script, you are, in effect, driving the Find/Change feature of the UI, so whatever happens there or is available there happens in scripts or is available to scripts. Look at the Applications findPreferences and changePreferences.

                  Dave
                  • 6. Re: [js] [cs2] Apply paragraph style
                    Level 1
                    Hi Dave,

                    I can't deny Adobe has a massive number of pages documenting the object structure of it's applications. I no longer count the available pages.
                    I also don't argue that this is more than enough for a experienced programmers...

                    However, I do have some basic programmers skills but I'm not familiar with the object structure of indesign. I don't know where everything is stored.

                    I think for those people who would like to use the scripting features but lake the routine, some small things would be nice to be added or changed in the future. A very small example, just a few lines, demonstrating the use of every class and its properties would be nice. I also hope that the ExtendedScript Toolkit will improve. I do miss the level of autocompletion of code like visual studio. Or maybe I'm just to demanding...

                    However, I do enjoy talking about different approaches of reaching a goal... I thank god that there are people like you and others, willing to help other people.... Keep up the good work....

                    Tim
                    • 7. Re: [js] [cs2] Apply paragraph style
                      Level 1
                      I'm a bit confused. Autocompletion is a feature of ESTK2 which works with InDesign CS3, but you seem to be working with CS2, so you should be using ESTK, which, I don't think, had autocompletion.

                      Dave
                      • 8. Re: [js] [cs2] Apply paragraph style
                        Level 1
                        Hi Dave

                        Your absolutly right... Currently I'm working on some things for CS2-files, to be executed in CS2, written in ESTK. When writing code for CS3, I use ESTK2....

                        Tim