Back

If your email is not recognized and you believe it should be, please contact us.

  • You must be logged in to reply to this topic.Login

Paragraph Based on style script

Return to Member Forum

  • Author
    Posts
    • #1187852
      Rick Soldin
      Participant

      I 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

    • #14324054
      Robert Ploch
      Member

      Hi 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.

    • #14324053
      Robert Ploch
      Member

      undefined means – there is no basedOn style …. ofcorse :)

    • #14324052
      Rick Soldin
      Participant

      Appreciate 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: ‘

    • #14324051
      Robert Ploch
      Member

      Hmmmmm,
      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?

    • #14324050
      Rick Soldin
      Participant

      Robert,

      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.

    • #14324049
      Robert Ploch
      Member

      the error on line 10 must mean something elese
      if there is no “basement” :) style you should get UNDEFINED

      try to delete line 10 :)

    • #14324048
      Rick Soldin
      Participant

      I 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.

    • #14324047
      Robert Ploch
      Member

      my 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 :)

    • #14324037
      Robert Ploch
      Member

      Rick
      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.

    • #14324035
      Rick Soldin
      Participant

      Robert,

      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

    • #14324030
      Robert Ploch
      Member

      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 } );
      }

    • #14324023
      Rick Soldin
      Participant

      Hi 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.com

      Thanks

    • #14323602

      I’m interested in this script as well, but I am also getting errors. Is there an updated one?

    • #14323587
      Robert Ploch
      Member

      Hi, 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

    • #14323584
      Year 1917
      Member

      Hi Robert
      Can you send it to me as well to year192017@gmail.com
      Thanks

Viewing 15 reply threads
  • You must be logged in to reply to this topic.
Forum Ads