CreativePro Forum
Join our community of graphic designers, publishers, and production artists from around the world. Our members-only forum is a great place to discuss challenges and find solutions!
- You must be logged in to reply to this topic.Login
Paragraph Based on style script
- This topic has 15 replies, 4 voices, and was last updated 6 years ago by
Robert Ploch.
-
AuthorPosts
-
-
September 26, 2019 at 7:17 am #1187852
Rick Soldin
ParticipantI have spent a good amount of time looking around for a script or extension that will list paragraph styles and what they are ‘based on’ if they are ‘based on’ another style. I found an old script but it doesn’t work in the current version of InDesign (14.0.3). I have received a template from a publisher which contains a large number of style sheets, both paragraph and character. Since I don’t use a lot of their stylesheets and I create my own when a modified incident is needed and am trying to remove handfuls of the exciting styles. I am finding a lot of their styles are ‘based on’ other styles which doesn’t help in removing the unused styles.
So, I was wondering if I was missing something in a way to track down this ‘based on’ styles. Somewhere in the past, I remember a script/extension that listed stylesheets and the ‘based on’ assignment. Is this now built into ID or is there a script/extension that I am not finding to help me with this.
Appreciate any help you can give.
Rick
-
September 26, 2019 at 12:08 pm #14324054
Robert Ploch
MemberHi Rick,
try this:
#target indesign-14
var ps = app.activeDocument.allParagraphStyles, cs = app.activeDocument.allCharacterStyles, parstyles = [], charstyles = [];
processStyles ( ps, 2, parstyles );
processStyles ( cs, 1, charstyles );var doc = app.documents.add( { pages : 2 } );
doc.pages[0].textFrames.add( { geometricBounds : [ ‘0mm’,’0mm’,’150mm’,’150mm’ ] } ).contents = ‘Paragraph styles: ‘ + parstyles.join( ”);
doc.pages[1].textFrames.add( { geometricBounds : [ ‘0mm’,’0mm’,’150mm’,’150mm’ ] } ).contents = ‘Character styles: ‘ + charstyles.join( ”);function processStyles ( s, x, a ) {
for ( var i = x; i < s.length; i++ ) {
var bs = s[i].basedOn.name;
a.push( s[i].name + ‘ ——— ‘ + bs );
}
}Just open your template and run the script from ExtendScript Toolkit
It is very simple solution that produces two lists in two frames in new document.I hope it will help you :)
redards
m. -
September 26, 2019 at 12:14 pm #14324053
Robert Ploch
Memberundefined means – there is no basedOn style …. ofcorse :)
-
September 26, 2019 at 12:32 pm #14324052
Rick Soldin
ParticipantAppreciate the quick response.
I ran the script and I get an error number: 8
Line: 9
Source: doc.pages[0].textFrames.add( { geometricBounds : [ ‘0mm’,’0mm’,’150mm’,’150mm’ ]}).contents = ‘Paragraph styles: ‘ + parstyles.join( ”);
Offending Text: ‘ -
September 26, 2019 at 12:39 pm #14324051
Robert Ploch
MemberHmmmmm,
I’ve tried this script on a few different documents and it works !try to exchange sigle quotes to double quotes – I use single but it is not exactly correct :)
do you use it om mac or pc?
-
September 26, 2019 at 12:40 pm #14324050
Rick Soldin
ParticipantRobert,
Yes, it was the copy and paste that took created curly quotes. After I fixed those, it ran but got an error 45 on line 10. I think it’s because I couldn’t find any Based On styles in the character styles.
-
September 26, 2019 at 12:44 pm #14324049
Robert Ploch
Memberthe error on line 10 must mean something elese
if there is no “basement” :) style you should get UNDEFINEDtry to delete line 10 :)
-
September 26, 2019 at 12:51 pm #14324048
Rick Soldin
ParticipantI removed line 10 and it works smooth, although nothing was listed for the character styles.
It didn’t add pages for overflow text but that’s easy to remedy.
This will work for what I need it for.
Thank you for taking the time.
-
September 26, 2019 at 12:55 pm #14324047
Robert Ploch
Membermy solution is in fact not as elegant as it could be, but my goal was to give you a quick solution. I very happy it help you :)
-
September 27, 2019 at 1:22 am #14324037
Robert Ploch
MemberRick
I made a big mistake yesterday. Replace line 8 with this code :doc = app.documents().documentPreferences.pagesPerDocument = 2;
It should make the script to run properly :)
best
m. -
September 27, 2019 at 5:03 am #14324035
Rick Soldin
ParticipantRobert,
I change line 8 to your replacement and I got an error 24 error string: ‘Object is not a function’ on line 8.
I added back the var and still got the error.Rick
-
September 27, 2019 at 3:25 pm #14324030
Robert Ploch
MemberHello 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 documentIf 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 } );
} -
September 28, 2019 at 8:11 am #14324023
Rick Soldin
ParticipantHi Robert,
I appreciate the work you are doing with this.
I ran the new listing and came up with
Error Number: 25 on line 10
Error string: Expected: )Here is my email so we can do this outside the forum.
rick@book-comp.comThanks
-
December 10, 2019 at 7:57 am #14323602
Julie ShafferMemberI’m interested in this script as well, but I am also getting errors. Is there an updated one?
-
December 10, 2019 at 11:41 am #14323587
Robert Ploch
MemberHi, Julie
Yes, I’ve improved the script in some cases (e.g. it can add as many pages od listing as it is needed), and I works fine for me. The best way to share the script is to send you it as a file direct to your e-mail, as we’ve done with Risk :). So please write me your e-mail and I’ll send you the script tonight or tomorrow. Best regards Robert -
December 10, 2019 at 8:39 pm #14323584
Year 1917
MemberHi Robert
Can you send it to me as well to year192017@gmail.com
Thanks
-
-
AuthorPosts
- You must be logged in to reply to this topic.
