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

Creating a Style List

Community Expert ,
Nov 07, 2011 Nov 07, 2011

I'm looking for a script that could list out the name of my styles and apply that style to the text in the list?

Something like this

Untitled-1.jpg

TOPICS
Scripting
6.5K
Translate
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

Community Expert , Nov 07, 2011 Nov 07, 2011

Short & sweet. Wasn't there a post on InDesignSecrets, by the way, doing the same? (Can't be bothered to look it up because this is way more fun.)

if (app.documents.length > 0 && app.selection.length == 1 && app.selection[0].hasOwnProperty("baseline"))

          for (p=2; p<app.activeDocument.allParagraphStyles.length; p++)

          {

                    name = app.activeDocument.allParagraphStyles

.name;

                    par = app.activeDocument.allParagraphStyles

.parent;

                    while

...
Translate
People's Champ ,
Nov 07, 2011 Nov 07, 2011

Which style do you want to apply to the text in the list? (Using email

and can't see the picture)

Ariel

Translate
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
People's Champ ,
Nov 07, 2011 Nov 07, 2011

Also, is it a list of paragraph styles that you want?

Plus, how do you want the script to deal with style groups?

Ariel

Translate
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
Community Expert ,
Nov 07, 2011 Nov 07, 2011

Just to list them out in the order they are in. From top to bottom.

Basically, the text should read the Style name, then apply that style to the text.

Heading 1

Heading 2

Heading 3

Body Text

Body Text Indent

and so on

Translate
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
People's Champ ,
Nov 07, 2011 Nov 07, 2011

I'm ignoring groups, and presuming we're on CS4 (and possibly upwards)

and that you've got your text cursor in an empty text frame, and I

haven't tested this much because I'm right in the middle of something,

but here goes:

myDoc = app.activeDocument;

myStyles = myDoc.allParagraphStyles;

myStory = app.selection[0].parentStory;

for (a=0; a<myStyles.length; a++){

myStory.insertionPoints[-1].contents = myStyles.name+"\r";

myStory.paragraphs[-1].appliedParagraphStyle = myStyles;

}

Does that help?

Ariel

Translate
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
Enthusiast ,
Nov 07, 2011 Nov 07, 2011

List of style carataires.
List of paragraph style and its réapliqué

For me it works, the code needs to be improved ...


Attention to the character in the names of styles (no (), ° §) it poses problems

Translation of French


Liste des style de carataires.

Liste des style de paragraphes et il son réapliqué

Pour moi ça marche, le code demande à être amélioré ...

Attention au caractère dans le nom des styles ( pas de (), °, §) sa pose des problème

var leNombreDeGroupeCara = app.activeDocument.characterStyleGroups.length; // conteur de groupr de style  para

var lesStyleDocCara = [];

lesStyleDocCara = styleDocCar();

if (leNombreDeGroupeCara != 0 ) {

for (i = 0; i < leNombreDeGroupeCara; i++) { // for 01

       var conteurStyle = app.activeDocument.characterStyleGroups.characterStyles.length;           

            for (y = 0; y < conteurStyle; y++) { // for 02

               lesStyleDocCara.push(app.activeDocument.characterStyleGroups.characterStyles.name);

            } // for 02

        } // fin du FOR 01      

    } else {

        alert(leNombreDeGroupeCara);

  } // fin du IF

var leNombreDeGroupePara = app.activeDocument.paragraphStyleGroups.length; // conteur de groupr de style  para

var lesStyleDoc = [];

lesStyleDoc = styleDocPara();

if (leNombreDeGroupePara != 0 ) { 

    for (i = 0; i < leNombreDeGroupePara; i++) { // for 01

        var conteurStyle = app.activeDocument.paragraphStyleGroups.paragraphStyles.length;       

            for (y = 0; y < conteurStyle; y++) { // for 02

               lesStyleDoc.push(app.activeDocument.paragraphStyleGroups.paragraphStyles.name);

            } // for 02

        } // fin du FOR 01

    } else {

        alert(leNombreDeGroupePara);

        //$.writeln (leNombreDeGroupePara);

} // fin du IF

myDoc = app.activeDocument;

myStory = app.selection[0].parentStory;

myStory.insertionPoints[-1].contents = "Style Cara\r";

for (a=0; a<lesStyleDocCara.length; a++){

   myStory.insertionPoints[-1].contents = lesStyleDocCara+"\r";

}

myStory.insertionPoints[-1].contents = "Style Para\r";

for (a=1; a<lesStyleDoc.length; a++){

   myStory.insertionPoints[-1].contents = lesStyleDoc+"\r";

   if (app.activeDocument.paragraphStyles.item(lesStyleDoc)){

       try{

        myStory.paragraphs[-1].appliedParagraphStyle = app.activeDocument.paragraphStyles.item(lesStyleDoc);

        }

        catch (e){

            var leStyle = lesStyleDoc;

            myStory.paragraphs[-1].appliedParagraphStyle = app.activeDocument.paragraphStyleGroups[0].paragraphStyles.item(leStyle);

        }

    }

  } //

function styleDocCar() {

     var variableLocal = app.activeDocument.characterStyles.everyItem().name.join("|");

     return variableLocal.split("|");

}// fin de 

function styleDocPara() {

     var variableLocal = app.activeDocument.paragraphStyles.everyItem().name.join("|");

     return variableLocal.split("|");

}// fin de

Translate
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
Enthusiast ,
Nov 07, 2011 Nov 07, 2011

Hi

I have treated one group of style, there should be a routine test in all the group!

Translation Frabçais

je n'ai traité qu'un seul groupe de style, il faudrais faire une routine qui test dans tous les groupe!

Philou

Translate
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
Community Expert ,
Nov 07, 2011 Nov 07, 2011

Short & sweet. Wasn't there a post on InDesignSecrets, by the way, doing the same? (Can't be bothered to look it up because this is way more fun.)

if (app.documents.length > 0 && app.selection.length == 1 && app.selection[0].hasOwnProperty("baseline"))

          for (p=2; p<app.activeDocument.allParagraphStyles.length; p++)

          {

                    name = app.activeDocument.allParagraphStyles

.name;

                    par = app.activeDocument.allParagraphStyles

.parent;

                    while (par instanceof ParagraphStyleGroup)

                              name = par.name+" : "+name, par = par.parent;

                    app.selection[0].parentStory.insertionPoints[-1].properties = {contents:name+"\r", appliedParagraphStyle:app.activeDocument.allParagraphStyles

};

          }

Translate
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
Participant ,
Dec 07, 2011 Dec 07, 2011
LATEST

Wow, always impressed! I added the Character style based on that script (changed all "Paragraph" to "Character" and  "p=2" to "p=1")

Translate
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
Community Expert ,
Nov 08, 2011 Nov 08, 2011

Thanks everyone. I liked Jongware's version it was a lot shorter and did exactly what I wanted.

Thanks everyone

Translate
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
Explorer ,
Nov 08, 2011 Nov 08, 2011

I Jongware,

This one is a very useful script for me and I supose for a lot of people. But it whould be better if it executes only with the paragrah styles that are inside a Style Group. Can you do this for me?

Thank you in advance

Maria

Translate
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
Community Expert ,
Nov 08, 2011 Nov 08, 2011

Yeah sure.

if (app.documents.length > 0 && app.selection.length == 1 && app.selection[0].hasOwnProperty("baseline"))

for (p=2; p<app.activeDocument.allParagraphStyles.length; p++)

{

  if (app.activeDocument.allParagraphStyles

.parent instanceof ParagraphStyleGroup)

  {

   name = app.activeDocument.allParagraphStyles

.name;

   par = app.activeDocument.allParagraphStyles

.parent;

   while (par instanceof ParagraphStyleGroup)

    name = par.name+" : "+name, par = par.parent;

   app.selection[0].parentStory.insertionPoints[-1].properties = {contents:name+"\r", appliedParagraphStyle:app.activeDocument.allParagraphStyles

};

  }

}

Translate
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
Community Expert ,
Nov 08, 2011 Nov 08, 2011

@Jongware:
Hm. Maybe it's better to set p=1 so we can catch the [Basic Paragraph] style.

Uwe

Translate
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
Community Expert ,
Nov 08, 2011 Nov 08, 2011

I intentionally skipped it because your documents can catch some contagious stuff from it!

(Interested lurchers: I started with index #2 because

#0 is [No Paragraph Style]

#1 is [Basic Paragraph Style]

Including [No Paragraph Style] is useless, as it's always equal to [Basic]. [Basic] can be redefined and used; however, I think in general it's advised not to, because copying text with a Basic style or one based on it to a document with a different definition Will Mess You Up.)

Translate
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
Community Expert ,
Nov 08, 2011 Nov 08, 2011

I'm glad you skipped the Basic Paragraph Style - it's not needed at all. It shouldn't even be in the program from the start.

Translate
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
Enthusiast ,
Nov 08, 2011 Nov 08, 2011

Hear, hear!

Translate
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
Explorer ,
Nov 08, 2011 Nov 08, 2011

Thank you very much

Maria

Translate
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
Enthusiast ,
Nov 08, 2011 Nov 08, 2011

Congratulations class! [Jongware]

Translate
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