Skip to main content
Inspiring
March 7, 2018
Question

Apply object style in a paragraph style

  • March 7, 2018
  • 3 replies
  • 1382 views

In the first image, I have the text box with the paragraph style "título_abertura_UND" .

I need to apply the object style "sombra_titulo_UND" only in texts that have the paragraph style "título_abertura_UND". So you can stay as in the picture below.

The help of friends will be of great importance, thank you very much.

This topic has been closed for replies.

3 replies

Anantha Prabu G
Legend
March 8, 2018

Hi,

Hope this helps!!

var myDoc = app.documents[0];

app.findTextPreferences = app.changeTextPreferences = null;

app.findTextPreferences.appliedParagraphStyle="Para";  // Change the para style name

var myFind = myDoc.findText();

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

{

   

myText = app.findTextPreferences.appliedParagraphStyle="Para";  // Change the para style name

    

myText.contents=myFind.contents;

myFind.parentTextFrames[0].appliedObjectStyle = myDoc.objectStyles.item("A");  // Change the Object style name

   

app.findTextPreferences = app.changeTextPreferences = null;

Thanks,

Prabu G

Design smarter, faster, and bolder with InDesign scripting.
Inspiring
March 7, 2018

I found a resolution to my problem !

var doc = app.activeDocument; 

var i, link, newFileLocal, newFilePDF, newFileEPS,

links = doc.links,

newPathPDF = '/way/';

newPathEPS = '/way/';

var countFileLocal = 0;

var countFilePDF = 0;

var countFileEPS = 0;

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

    link = links;

    newFileLocal = new File(doc.filePath + "/Links/"+ link.name);

    newFilePDF = new File(newPathPDF + link.name);

    newFileEPS = new File(newPathEPS + link.name);

    if (newFileLocal.exists) {

        link.relink(newFileLocal);

        countFileLocal ++;

        }

    if (newFilePDF.exists) {

        link.relink(newFilePDF);

        countFilePDF ++;

        }

    if (newFileEPS.exists) {

        link.relink(newFileEPS);

        countFileEPS ++;

        }

}

Thanks.

Inspiring
March 7, 2018

Seems pretty straightforward:

1) Set your findText (or findGrep) preferences to catch the "abuerta" paragraph style.

2) Use the findText() or findGrep() method to get an array of all the text objects using that paragraph style.

3) Loop through that array and apply the "sombra" object style to the .parentTextFrame of each text object.  Be sure to test with two or more paragraphs using abuerta in the same text frame. Your script will apply the object style multiple times to that frame. But it's probably a nonproblem.

If all that works, then you have to think about a way to make sure the script gets run at the proper time. Maybe it's just a matter of alerting your designers to remember to do it. Or it could be hooked up to a "beforeSave" or "beforeClose" event listener.

You're probably aware that you can associate a particular paragraph style with an object style. If all of your sombra text frames  are supposed to use the abuerta style, you can make that happen when the frame is created.

Hope this helps.

Bob