Convert Paragraph to Table and apply table style

Learn / Forums / InDesign Add-ons (Scripts, Scripting, and Plug-ins) / Convert Paragraph to Table and apply table style

Tagged: , ,

Viewing 4 reply threads
  • Author
    Posts
    • #70878
      Bart Eenkhoorn
      Participant

      L.S.
      I found this great script to convert paragraphs (paragraph styles) to tables and apply a table style. It works great but I would like it to run for all the documents in my book. I normally use this ‘umbrella’ to run scripts for all documents in a book, but for some reason I can’t get it to work. Thanks in advance for any help.

      book = app.activeBook;

      for (var i=0; i<book.bookContents.length; i++)
      {
      var currentDoc = app.open (book.bookContents[i].fullName, false);

      // DO THINGS HERE FOR EVERY BOOK

      currentDoc.close(SaveOptions.YES);
      }

      Script to convert Paragraph to Table and apply table style
      ==================
      app.findGrepPreferences = null;
      app.findGrepPreferences.appliedParagraphStyle = app.documents.firstItem().paragraphStyles.itemByName( ‘PARAGRAPH STYLE NAME HERE’ );

      var result = app.documents.firstItem().findGrep();
      for (var i = result.length-1; i >= 0; i–)

      {
      var a_text =(result[i].characters.lastItem().contents == ‘\r’)
      ? result[i].parentStory.characters.itemByRange(result[i].characters.firstItem().index, result[i].characters.lastItem().index -1)
      : result[i];
      var a_table = a_text.convertToTable( );
      }

      app.findGrepPreferences = null;
      var d = app.activeDocument;
      var myTableStyle = myDisplayDialog ();

      d.stories.everyItem().tables.everyItem().appliedTableStyle = myTableStyle;
      d.stories.everyItem().tables.everyItem().clearTableStyleOverrides( true );

      function myDisplayDialog(){
      var myDialog = app.dialogs.add({name:”Choose a table style”});
      with(myDialog.dialogColumns.add()){
      var myTsDropDown = dropdowns.add({stringList: d.tableStyles.everyItem().name, selectedIndex:d.tableStyles.length-1});
      }
      var myResult = myDialog.show();
      if(myResult == true){
      var tS = d.tableStyles[myTsDropDown.selectedIndex];
      myDialog.destroy();
      }
      else{
      myDialog.destroy();
      exit()
      }
      return tS;
      }

    • #70879
      Bart Eenkhoorn
      Participant

      P.S. Is there a way to make code-lines more readable in forum posts? My post is not very user-friendly :-(
      Bart

    • #70883
      David Blatner
      Keymaster

      Bart: yeah, we don’t have any special code-processing on the forum here, that I know of. However, I usually find it’s better if you wrap it in an html code tag, then it comes out:

      Like this;

      (I’m not a scripter, but I know enough to put a semicolon in there! ;-)

    • #74385
      Poleroad
      Member

      Hello B. Eenkhoorn,

      I found your script very helpful, if I could make it work for me. That is Convert Paragraph to Table and Apply Table Style. If you have a minute for hand-holding, the script bombs on line 15 and also on the following line:
      for (var i = result.length-1; i >= 0; i-)

      Could you post a more readable version?

      Thank you,
      Martin

    • #74386
      Poleroad
      Member

      Hello B. Eenkhoorn,

      I found your script very helpful, if I could make it work for me. That is Convert Paragraph to Table and Apply Table Style. If you have a minute for hand-holding, the script bombs on line 15 and also on the following line:
      for (var i = result.length-1; i >= 0; i-)

      Could you post a more readable version?

      Thank you,
      Martin

Viewing 4 reply threads
  • You must be logged in to reply to this topic.
>