3 Replies Latest reply on Jul 15, 2011 2:50 AM by Trevorׅ

    Current paragraph style script

    Trevorׅ Adobe Community Professional

      Can somebody tell me what is the code to return the paragraph style for the current cursor position.

      Also I can I apply something to the the current paragragh not useing pragraph styles.

      For example what would be the code for "Make current paragraph text Red".

       

      Help would be much appreciated as one can see from the questions I am a complete novice in scripting.

        • 1. Re: Current paragraph style script
          2i_Geert Level 1

          Hi,

           

          Do you mean something like this:

           

          var document = app.documents.add();
          var textFrame = document.textFrames.add();

          textFrame.geometricBounds = [30, 30, 200, 300];
          textFrame.contents = "Hello InDesign World\rSecond Paragraph\rThird Paragraph";
          textFrame.recompose();

           

          if(textFrame.paragraphs.length > 2)
          {
              // Get the second paragraph
              var paragraph = textFrame.paragraphs[1];
              var redColor = document.colors.add({colorValue: [255, 0, 0], space: ColorSpace.RGB});
             
              // Make second paragraph bigger and red
              paragraph.pointSize = 24;
              paragraph.fillColor = redColor;
          }

          • 2. Re: Current paragraph style script
            Kasyan Servetsky Level 5
            if (app.documents.length > 0 && app.selection.length === 1 && app.selection[0].hasOwnProperty("baseline")) {
                 // return the paragraph style for the current cursor position
                 alert("Paragraph style: " + app.selection[0].appliedParagraphStyle.name);
                 // Make current paragraph text Red (the 1st paragraph in the selection)
                 app.selection[0].paragraphs[0].fillColor = "C=15 M=100 Y=100 K=0";
            }
            
            • 3. Re: Current paragraph style script
              Trevorׅ Adobe Community Professional

              Thanks a lot 100% exactly what I wanted.