Skip to main content
Known Participant
December 19, 2011
Question

Remove indent after paragraph

  • December 19, 2011
  • 2 replies
  • 2318 views

I'm new to scripting and I have a problem that scripting might be able to fix.

I have body text with indent but after headlines in the body text the indent sholud be removed. My editorial program only allowes me to use one paragraph style for the body text. When the text is placed on the page everything works fine because the editorial program fixes the text so that indent after headlines in the body text are removed.

But when the pagemakers move the hadlines the indent doesn't follow. Making indents is simple by using the paragraph style and to remove the indent I now use a script.

THis made me thinking.

Is it possible for a script to:

1. Identify all headlines in the body text (the paragraph style is called Mellanrubrik)

2. Remove the indent on the body text paragraph that follows

I have tried using this but I don't know what to write between the commands.

if (appliedParagraphStyle=Mellanrubrik)

app.selection[0].firstLineIndent=0

Best regar

ds

Mikael Wiik, Sweden

This topic has been closed for replies.

2 replies

Jump_Over
Legend
December 19, 2011

allParagraphStyles gives Array of objects not a collection, so item(), firstItem(), ... etc doesn't works. Use paragraphStyleGroups.item("YourGroupName") before paragraphStyles:

line3:

app.findTextPreferences.appliedParagraphStyle

= app.activeDocument.paragraphStyleGroups.item("YourGroupName").paragraphStyles.item("Mellanrubrik");

John Hawkinson
Inspiring
December 19, 2011

Whoops! Good point, thanks for the correction, Jump_Over!

Jongware
Community Expert
Community Expert
December 19, 2011

That's a reasonable starting point. First off, you cannot simply use the name of your style; you need to 'look it up' using "app.activeDocument.paragraphStyles.item("Mellanrubrik")". Second, if you use the Find function to locate your heads, the 'selection' will not 'hold' the next paragraph. There are several ways to increment the, uh, 'cursor' (not really) to the next paragraph, but the easiest way is to use 'nextItem' on the Found Item's paragraph object.

With those adjustments, your little scriptlet works once only, and the next step would be to make it work on an entire document:

1. Find all headlines.

2. For each of the found headlines,

   a. Check if the next paragraph is your body text (I'd advise this check)

   b. If so, set its indent to '0'.

(Fill in the name of your body text paragraph style below.)

// 1. Find a list of all headers

app.findTextPreferences = null;

app.findTextPreferences.appliedParagraphStyle = app.activeDocument.paragraphStyles.item("Mellanrubrik");

list = app.activeDocument.findText(0);

// 2. For each found item ...

for (i=0; i<list.length; i++)

{

// a. Check the *next* paragraph for your body text

if (list.paragraphs.nextItem(list.paragraphs[0]).appliedParagraphStyle == app.activeDocument.paragraphStyles.item("Body Text"))

// b. If so, remove indent

  list.paragraphs.nextItem(list.paragraphs[0]).firstLineIndent = 0;

}

A disadvantage, however, would be that moving the headers around will also have left other paragraphs without an indent that should have one!

You could consider to duplicate your body text style, set the indent to 0, and name it something like "Body Text After Head" -- that way you don't get a nasty "override +" -- and apply this instead of the override. When you notice someone else moved stuff around, delete this new style (!!) and replace it with your plain body text. Then re-create the style and run the script again.

Known Participant
December 19, 2011

Hi and thanks for the help

I added my body text paragraph style and tested the script. However I got an error message, unfortunately in swedish but I will try to translate it.

---------------------------
Adobe InDesign
---------------------------
JavaScript Fel.

Felkod: 30477
Felsträng: Ogiltigt värde angett för egenskapen appliedParagraphStyle. String, ParagraphStyle or NothingEnum enumerator förväntades, nothing togs emot.

Motor: main
Fil: C:\Program\Adobe\Adobe InDesign CS5.5\Scripts\Scripts Panel\Samples\JavaScript\Kopia av Ta bort indrag.jsx
Rad: 3
Källa: app.findTextPreferences.appliedParagraphStyle = app.activeDocument.paragraphStyles.item("Mellanrubrik");
---------------------------
OK  
---------------------------

---------------------------
Adobe InDesign
---------------------------
JavaScript Error.

Errorcode: 30477
Error string: Invalid value set for appliedParagraphStyle. String, ParagraphStyle or NothingEnum enumerator was expected, nothing was recieved.

Motor: main
File: C:\Program\Adobe\Adobe InDesign CS5.5\Scripts\Scripts Panel\Samples\JavaScript\Kopia av Ta bort indrag.jsx
Row: 3
Source: app.findTextPreferences.appliedParagraphStyle = app.activeDocument.paragraphStyles.item("Mellanrubrik");
---------------------------
OK  
---------------------------

Hope you can make any sense out of this.

BR,

Mikael Wiik

John Hawkinson
Inspiring
December 19, 2011

Is your Mellanrubrik part of a style group? Try allParagraphStyles instead of paragraphStyles.