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

Remove unused paragraph styles while keeping in mind based on styles

New Here ,
Jul 31, 2017 Jul 31, 2017

Copy link to clipboard

Copied

i was trying to remove unused paragraph styles the same way as indesign do it while keeping in mind the basedon property but it is still not working properly

here is my code and i dont know the problem

var myParStyles = app.activeDocument.paragraphStyles;

var flag = true;

for (i = myParStyles.length-1; i >= 2; i--){

   app.findTextPreferences = app.changeTextPreferences = NothingEnum.nothing;

   app.findTextPreferences.appliedParagraphStyle = myParStyles

   var myFoundStyles = app.activeDocument.findText(); 

   if (myFoundStyles == 0) {

for (x = myParStyles.length-1; x >= 2; x--){

if (myParStyles.basedOn.name == myParStyles.name) {

app.findTextPreferences = app.changeTextPreferences = NothingEnum.nothing;     

app.findTextPreferences.appliedParagraphStyle = myParStyles

var myFoundStyles1 = app.activeDocument.findText();

if (myFoundStyles1 == 0) {myParStyles.remove();}

flag = false; break;}}

if (flag) {myParStyles.remove();}}}

alert("Done");

Views

697

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

Adobe Employee , Jul 31, 2017 Jul 31, 2017

Hi,

I made the below script in a hurry and did not test extensively, but it works for me...

var myDoc = app.activeDocument;

var myParStyles = myDoc.paragraphStyles;

for (i = myParStyles.length-1; i >= 2;i-- )

{

    var itr=0;

    itr=removeUnusedParaStyle(myParStyles);

    alert(myParStyles.name);

    if(itr==1)

       myParStyles.remove();

}

function removeUnusedParaStyle(myPaStyle)

{

  app.findTextPreferences = app.changeTextPreferences=null;

  app.findTextPreferences.appliedParagraphStyle = myPaStyle;

...

Votes

Translate

Translate
Adobe Employee ,
Jul 31, 2017 Jul 31, 2017

Copy link to clipboard

Copied

Hi,

I made the below script in a hurry and did not test extensively, but it works for me...

var myDoc = app.activeDocument;

var myParStyles = myDoc.paragraphStyles;

for (i = myParStyles.length-1; i >= 2;i-- )

{

    var itr=0;

    itr=removeUnusedParaStyle(myParStyles);

    alert(myParStyles.name);

    if(itr==1)

       myParStyles.remove();

}

function removeUnusedParaStyle(myPaStyle)

{

  app.findTextPreferences = app.changeTextPreferences=null;

  app.findTextPreferences.appliedParagraphStyle = myPaStyle;

  var myFoundStyles = myDoc.findText();

      if (myFoundStyles == 0)

        {

                for (var k = myParStyles.length-1; k >= 2; k-- ) 

                {

                if (myParStyles.basedOn.name == myPaStyle.name)

                    return 0;           

                }

            return 1;

         }

       return 0;

}

In the script, a paragraph style "p" will be considered unused when

1. Document has no text with that style applied

2. And no other style is based on "p"

InDesign however considers a style "p" unused when no other style is based on "p"

Indesign will consider a style "p" used, even if an empty paragraph (with no text) has that style applied.

Example: If i create 2 style p1 and p2 and make a blank frame with p1 selected, then InDesign will consider only p2 unused. The script above will consider both p1 and p2 unused.

Let me know if this helps.

-Aman

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
New Here ,
Aug 01, 2017 Aug 01, 2017

Copy link to clipboard

Copied

LATEST

many thanks to you i think it works fine now, but is there any way to improve it or it is fine as it is

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