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
- This topic has 5 replies, 3 voices, and was last updated 8 years, 12 months ago by Poleroad.
-
AuthorPosts
-
-
October 3, 2014 at 8:43 am #70878Bart EenkhoornParticipant
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;
} -
October 3, 2014 at 8:49 am #70879Bart EenkhoornParticipant
P.S. Is there a way to make code-lines more readable in forum posts? My post is not very user-friendly :-(
Bart -
October 3, 2014 at 3:25 pm #70883David BlatnerKeymaster
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! ;-)
-
October 18, 2014 at 8:19 am #71116Bart EenkhoornParticipant
Thanks for the tip David. In the meantime (seek and you will find) I found the answer to my question in the form of a gem-script written by Martin Fischer and improved by Uwe Laubender. The script is called DOSCRIPT_with_Docs_of_Book_WITH_save_close.jsx and you can find it here:
Bart.
-
-
April 3, 2015 at 11:32 am #74385PoleroadMember
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 -
April 3, 2015 at 11:33 am #74386PoleroadMember
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
-
-
AuthorPosts
- You must be logged in to reply to this topic.