Sort by Name via script
Hi everybody,
I would appreciate if someone could give some clue to sort by name the
Paragraph Styles, Character Styles, Object Styles and Swatches panels
via script.
Thank you all in advance.
Edson Furman
Hi everybody,
I would appreciate if someone could give some clue to sort by name the
Paragraph Styles, Character Styles, Object Styles and Swatches panels
via script.
Thank you all in advance.
Edson Furman
For sorting styles I have used the script listed below -- works in CS3 and CS4 though it's been a while since I last tried. It could be coded more elegantly but it always worked fine as it is. It doesn't take into account any style groups -- I don't know what happens if your documents contain any so you'd better not try.
As to swatches, these are not so easy to sort. There was some discussion about this at either of these sites:
http://www.hilfdirselbst.ch/gforum/gforum.cgi?jump=forum%3D4
http://indesign-faq.de/
Peter
#target indesign
sort_par_styles (app.documents[0]);
sort_char_styles (app.documents[0]);
sort_obj_styles (app.documents[0]);
//-------------------------------------------------------------------------------
function sort_par_styles (doc)
{
var string_array = sort_par_names (doc);
for (var i = 0; i < string_array.length; i++)
doc.paragraphStyles.item (string_array).move (
LocationOptions.after, doc.paragraphStyles[i+2])
}
function sort_par_names (doc)
{
var array = doc.paragraphStyles.everyItem().name;
array.shift (); array.shift (); // exclude [No p.] and [Basic p/]
return array.sort (case_insensitive);
}
//-------------------------------------------------------------------------------
function sort_char_styles (doc)
{
var string_array = sort_char_names (doc);
for (var i = 0; i < string_array.length; i++)
doc.characterStyles.item (string_array).move (
LocationOptions.after, doc.characterStyles[i+1])
}
function sort_char_names (doc)
{
var array = doc.characterStyles.everyItem().name;
array.shift (); // exclude [None]
return array.sort (case_insensitive);
}
//-------------------------------------------------------------------------------
function sort_obj_styles (doc)
{
var string_array = sort_obj_names (doc);
for (var i = 0; i < string_array.length; i++)
doc.objectStyles.item (string_array).move (
LocationOptions.after, doc.objectStyles[i+4])
}
function sort_obj_names (doc)
{
var array = doc.objectStyles.everyItem().name;
array.shift (); array.shift (); array.shift (); array.shift (); // exclude [None], [Basic Graphics Frame], [Basic Text Frame], [Basic Grid]
return array.sort (case_insensitive);
}
//-------------------------------------------------------------------------------
function case_insensitive (a, b)
{
return a.toLowerCase() > b.toLowerCase()
}Already have an account? Login
Enter your E-mail address. We'll send you an e-mail with instructions to reset your password.