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.
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
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);
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);
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
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 ![]()
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.
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
North America
Europe, Middle East and Africa
Asia Pacific