Skip navigation
Currently Being Moderated

Creating a Style List

Nov 7, 2011 8:50 AM

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

 
Replies
  • Currently Being Moderated
    Nov 7, 2011 8:56 AM   in reply to Eugene Tyson

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

    and can't see the picture)

     

    Ariel

     
    |
    Mark as:
  • Currently Being Moderated
    Nov 7, 2011 8:58 AM   in reply to Eugene Tyson

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

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

     

    Ariel

     
    |
    Mark as:
  • Currently Being Moderated
    Nov 7, 2011 10:22 AM   in reply to Eugene Tyson

    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[a].name+"\r";

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

    }

     

    Does that help?

     

    Ariel

     
    |
    Mark as:
  • Currently Being Moderated
    Nov 7, 2011 1:51 PM   in reply to Eugene Tyson

    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[i].characterStyles.length;            

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

                   lesStyleDocCara.push(app.activeDocument.characterStyleGroups[i].chara cterStyles[y].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[i].paragraphStyles.length;        

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

                   lesStyleDoc.push(app.activeDocument.paragraphStyleGroups[i].paragraph Styles[y].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[a]+"\r";

    }

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

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

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

       if (app.activeDocument.paragraphStyles.item(lesStyleDoc[a])){

           try{

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

            }

            catch (e){

                var leStyle = lesStyleDoc[a];

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

            }

        }

      } //

    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

     
    |
    Mark as:
  • Currently Being Moderated
    Nov 7, 2011 2:12 PM   in reply to Eugene Tyson

    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

     
    |
    Mark as:
  • Currently Being Moderated
    Nov 7, 2011 2:24 PM   in reply to Eugene Tyson

    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[p].name;
                        par = app.activeDocument.allParagraphStyles[p].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[p]};
              }
    
     
    |
    Mark as:
  • Currently Being Moderated
    Calculating status...
    Nov 8, 2011 5:06 AM   in reply to Eugene Tyson

    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

     
    |
    Mark as:
  • Currently Being Moderated
    Nov 8, 2011 5:51 AM   in reply to Maria964

    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[p].parent instanceof ParagraphStyleGroup)
      {
       name = app.activeDocument.allParagraphStyles[p].name;
       par = app.activeDocument.allParagraphStyles[p].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[p]};
      }
     }
    
     
    |
    Mark as:
  • Currently Being Moderated
    Nov 8, 2011 6:17 AM   in reply to [Jongware]

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

     

    Uwe

     
    |
    Mark as:
  • Currently Being Moderated
    Nov 8, 2011 6:38 AM   in reply to Laubender

    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.)

     
    |
    Mark as:
  • Currently Being Moderated
    Nov 8, 2011 7:39 AM   in reply to Eugene Tyson

    Hear, hear!

     
    |
    Mark as:
  • Currently Being Moderated
    Nov 8, 2011 9:23 AM   in reply to [Jongware]

    Thank you very much

     

    Maria

     
    |
    Mark as:
  • Currently Being Moderated
    Nov 8, 2011 9:32 AM   in reply to Eugene Tyson

    Congratulations class! [Jongware]

     
    |
    Mark as:
  • Currently Being Moderated
    Dec 7, 2011 6:51 AM   in reply to [Jongware]

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

     
    |
    Mark as:

More Like This

  • Retrieving data ...

Bookmarked By (0)

Answers + Points = Status

  • 10 points awarded for Correct Answers
  • 5 points awarded for Helpful Answers
  • 10,000+ points
  • 1,001-10,000 points
  • 501-1,000 points
  • 5-500 points