Hello again Rick,
there is a modified and improoved, more elegant version of the script :-)
I hope it will work fine for you …
The changes are:
1. script returns only styles if they have baseOn style
2. if there are no baseOn styles in character styles, script opens only one paged document
3. I put the original numbers of the styles in source document
If you will have still problems with the script write your e-mail, so I will send you a file.
regards
m.
#target indesign-14
if ( !app.documents.length ) { alert ( “Open document, please !” ); exit(); }
var ps = app.activeDocument.allParagraphStyles, cs = app.activeDocument.allCharacterStyles, parstyles = [], charstyles = [];
processStyles ( ps, 2, parstyles );
processStyles ( cs, 1, charstyles );
if ( parstyles.length > 0 && charstyles.length == 0 ) {
var doc = app.documents.add();
addTitleStyle (); addSubTitleStyle();
with ( doc.documentPreferences ) { pagesPerDocument = 1; }
var p = doc.pages[0];
with ( p.marginPreferences ) { top = 10; left = 10; bottom = 10; right = 10; }
p.textFrames.add( { geometricBounds : [ p.marginPreferences.top, p.marginPreferences.left, doc.documentPreferences.pageHeight – p.marginPreferences.bottom, doc.documentPreferences.pageWidth – p.marginPreferences.right ] } ).contents = “Paragraph styles: \rNo. Style based on\r” + parstyles.join( “\r” );
titleSubtitleBold( p.textFrames[0] );
alert (‘There is no basedOn character styles.’ );
}
else if ( parstyles.length > 0 && charstyles.length > 0 ) {
var doc = app.documents.add();
addTitleStyle (); addSubTitleStyle();
with ( doc.documentPreferences ) { pagesPerDocument = 2; }
var p = doc.pages; i = p.length;
while ( i– ) {
with ( p[i].marginPreferences ) { top = 10; left = 10; bottom = 10; right = 10; }
p[i].textFrames.add( { geometricBounds : [ p[i].marginPreferences.top, p[i].marginPreferences.left, doc.documentPreferences.pageHeight – p[i].marginPreferences.bottom, doc.documentPreferences.pageWidth – p[i].marginPreferences.right ] } );
}
p[0].textFrames[0].contents = “Paragraph styles: \rNo. Style based on\r” + parstyles.join( “\r” );
p[1].textFrames[0].contents = “Character styles: \rNo. Style based on\r” + charstyles.join( “\r” );
titleSubtitleBold ( p[0].textFrames[0] ); titleSubtitleBold ( p[1].textFrames[0] );
}
// ++++++++++++++++++++++++ func ++++++++++++++++++++++++++
function processStyles( s, x, a ) {
for ( var i = x; i < s.length; i++ ) {
var bs = s[i].basedOn.name;
if ( bs != undefined ) {
a.push( i + “\. ” + s[i].name + ‘ ——— ‘ + bs );
}
}
}
function titleSubtitleBold ( frame ) {
frame.parentStory.paragraphs[0].applyParagraphStyle( doc.paragraphStyles.item( “Title” ) );
frame.parentStory.paragraphs[1].applyParagraphStyle( doc.paragraphStyles.item( “SubTitle” ) );
}
function addTitleStyle ( ) {
doc.paragraphStyles.add( { name : “Title”, fontStyle : “Bold”, pointSize : 16 } );
}
function addSubTitleStyle ( ) {
doc.paragraphStyles.add( { name : “SubTitle”, fontStyle : “Bold”, pointSize : 14, fillTint : 50 } );
}