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

Current paragraph style script

Guru ,
Jul 14, 2011 Jul 14, 2011

Copy link to clipboard

Copied

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.

TOPICS
Scripting

Views

1.6K

Translate

Translate

Report

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

Guru , Jul 14, 2011 Jul 14, 2011

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";
}

Votes

Translate

Translate
Explorer ,
Jul 14, 2011 Jul 14, 2011

Copy link to clipboard

Copied

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;
}

Votes

Translate

Translate

Report

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
Guru ,
Jul 14, 2011 Jul 14, 2011

Copy link to clipboard

Copied

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";
}

Votes

Translate

Translate

Report

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
Guru ,
Jul 15, 2011 Jul 15, 2011

Copy link to clipboard

Copied

LATEST

Thanks a lot 100% exactly what I wanted.

Votes

Translate

Translate

Report

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