Skip navigation
P.Parthiban
Currently Being Moderated

How to Get all paragraph style which are used in the document

Jul 18, 2012 3:53 AM

Greetings,

 

Is there any option to get all paragraph styles, which are used in the document, directly? no need to find text for each and every paragraph style (i.e  find text count =0 ).

 

Regards,

Parthiban Paramanathan.

 
Replies
  • Currently Being Moderated
    Jul 18, 2012 9:22 AM   in reply to P.Parthiban

    Hi Parthiban,

     

    Try this code, even me also fresher:

     

     

    var myParagraphStyles = app.activeDocument.paragraphStyles.everyItem().getElements();

     

    or

     

    var myParagraphStyles = app.activeDocument.paragraphStyles;

     

     

    What the above line do is (All paragraph styles in the document stored in the myParagraphStyles variable)

     

    Tell your proper requirement.

     

    I try to give my solution....

     

    Regards

    Learner X

     
    |
    Mark as:
  • Currently Being Moderated
    Nov 9, 2012 4:50 AM   in reply to P.Parthiban

    No 'easy' solution, because a paragraph style can be used in a story, but also in footnotes, tables, anchored objects, etc. (and nested objects as well).

     

    One sure way is to search for *all* text, gather its assigned styles, and remove any duplicates:

     

    app.findGrepPreferences = null;
    app.findGrepPreferences.findWhat = ".*";
    l = app.activeDocument.findGrep();
    s = {};
    for (i=0; i<l.length; i++)
    s[l[i].appliedParagraphStyle.name] = 1;
    r = [];
    for (i in s)
    r.push (i);
    alert (r);
    
     
    |
    Mark as:
  • Currently Being Moderated
    Nov 9, 2012 4:53 AM   in reply to [Jongware]

    Slight enhancement. The above code fails if you have a style called 'reflect'. (Bonus points for the first -- other than Marc, Peter, John, or Uwe -- who can tell why.)

     

    app.findGrepPreferences = null;
    app.findGrepPreferences.findWhat = ".*";
    l = app.activeDocument.findGrep();
    s = {};
    for (i=0; i<l.length; i++)
    s[' '+l[i].appliedParagraphStyle.name] = 1;
    r = [];
    for (i in s)
    r.push (i.substr(1));
    alert (r);
    
     
    |
    Mark as:
  • Currently Being Moderated
    Nov 9, 2012 5:03 AM   in reply to P.Parthiban

    No, there's no option for that. It can be scripted, though:

     

    - get all paragraph styles (app.activeDocument.allParagraphStyles)

    - for each par. style, do a grep search for ^. using that par. style

    - if you found something, add the style's name to an array (also add the name of "based on" style, if any), avoiding the addition of duplicates

    - display the array

     

    Peter

     
    |
    Mark as:
  • Currently Being Moderated
    Nov 9, 2012 5:12 AM   in reply to [Jongware]

    Looking for ^. is probably more efficient than looking for ^.* since you need just one character to get a paragraph style, not the whole paragraph.

     

    Peter

     
    |
    Mark as:
  • Currently Being Moderated
    Nov 9, 2012 6:20 AM   in reply to [Jongware]

    Hi,

     

    In case of Bonus race:

    •   I started to run when found out it is going to  assign "1" to "read only" object  property;
    •   I step out from the road when tried to figure out why "constructor" style go through this with no error...

     

    rgds

     
    |
    Mark as:
  • Currently Being Moderated
    Nov 9, 2012 6:54 AM   in reply to Peter Kahrel

    Hi,

    For someone it could be important "pro" for  ^.*

    I mean paraStyle applied to i.e. empty table cells to layout them with predefined format of content.

    ^. will exclude those, probably usefull, styles

     

    rgds

     
    |
    Mark as:
  • Currently Being Moderated
    Nov 9, 2012 6:59 AM   in reply to Jump_Over

    Good catch! But it turns out that ^ will work on empty paragraphs as well.

     

    Peter

     
    |
    Mark as:
  • Currently Being Moderated
    Nov 12, 2012 4:41 PM   in reply to Peter Kahrel

    Hi Parth

     

    This is my solution, No greps, it probably misses something as that's what it was originally design to do see http://forums.adobe.com/message/4807305#4807305 but give it a go.

     

    // Script to find ParagraphStyle in documents which are not just in content pasted from illustrator file
    // By Trevor more than based on my script from http://forums.adobe.com/message/4807396#4807396
    var   myParagraphStyle="",
            uniqueParagraphStyle = {}, n;
    if (app.documents[0].stories.everyItem().textStyleRanges.length > 0) ParagraphStyleIn (app.documents[0].stories.everyItem().textStyleRanges.everyItem().appliedParagraphStyle)        
    if (app.documents[0].stories.everyItem().tables.length > 0) ParagraphStyleIn (app.documents[0].stories.everyItem().tables.everyItem().cells.everyItem().textStyleRanges.everyItem().appliedParagraphStyle)
    if (app.documents[0].stories.everyItem().footnotes.length > 0) ParagraphStyleIn (app.documents[0].stories.everyItem().footnotes.everyItem().textStyleRanges.everyItem().appliedParagraphStyle)
    for (n in uniqueParagraphStyle) myParagraphStyle+=(uniqueParagraphStyle[n])+"\r";
    alert(myParagraphStyle)
    function ParagraphStyleIn (item)
        {
            var l = item.length;
            while (l--) uniqueParagraphStyle[item[l].name] = item[l].name;
         }
    

     

    I expect thanks and all that with in the next few months.  Learner X is still waiting for his.

    I think this method is quicker than Jongware (not to sure) when I am board in the bog I shall make up some document with a few thousand paragraphs and get the stopwatch out

     
    |
    Mark as:
  • Currently Being Moderated
    Nov 13, 2012 2:01 AM   in reply to Trevorׅ

    Trevor, it certainly is faster than GREPping, but by how much I cannot say.[*]

     

    .. stories.everyItem().textStyleRanges.everyItem().appliedParagraphStyle ..

     

    Are you sure about this? There can be lots of text style ranges inside each paragraph. On the other hand, using

     

    .. stories.everyItem().paragraphs.everyItem().appliedParagraphStyle ..

     

    you will inspect each single paragraph once, and only read one style.

     

    [*] Just tested. It's blindingly fast, by a factor 100 or so

     

    Anyway, it seems the OP lost interest, so it has become a purely academical question.

     
    |
    Mark as:
  • Currently Being Moderated
    Nov 13, 2012 11:26 AM   in reply to [Jongware]

    Hi Jongware,

     

    I used textStyleRanges and not paragraph (ranges) because using

    .. stories.everyItem().paragraphs.everyItem().appliedParagraphStyle

    will miss ...... I was at least half asleep (2:45am) when I changed the code that I wrote for finding all the used languages in a doc - which needs textStyleRanges - to this one.  For this case paragraphs is for sure better.

     

    As you put it everyItem() is blindingly fast, Greps a so so.

    The unique array function / trick I learnt from you here Thanks

    http://forums.adobe.com/message/4500105#4500105

     

    Maybe the OP will wake up either way...

     

    Regards

     

    Trevor

     
    |
    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