Difference between revisions of "Export list of frames and page numbers"
(Created page with "Here is a simple script to generate a text file with a list of all the frames, page by page. This was done with the idea of helping to create the raw material for a Table of C...")
Revision as of 18:52, 10 February 2017
Here is a simple script to generate a text file with a list of all the frames, page by page. This was done with the idea of helping to create the raw material for a Table of Contents, since apparently there are occasionally some problems with the built-in function.
The only requirements for the script is that you have a document open. There is a fileDialog() that asks for the name of the file you want to save the results to. You get a message saying it was successful. It wouldn't be so much work to alternatively (or in addition) load the text into a selected text frame that you created for the TOC.
Here is a small example of what you get. As you see this goes page by page. While it may look like the script looks for image frames first, it actually takes frames in the order they were created. The other thing I have done here is created a TOC Paragraph Style and applied it afterward.
#!/usr/bin/env python # -*- coding: utf-8 -*- # File: extract_frames.py - Extracts the names of text and image frames, # saving to a text file as a list with associated pages for each # # © 2017.02.09 Gregory Pittman # # This program is free software; you can redistribute it and/or modify # it under the terms of the GNU General Public License as published by # the Free Software Foundation; either version 2 of the License, or # (at your option) any later version. import scribus def exportText(textfile): page = 1 pagenum = scribus.pageCount() T =  content =  T.append('Table of Contents \n\n') while (page <= pagenum): scribus.gotoPage(page) d = scribus.getPageItems() strpage = str(page) for item in d: if (item == 4): T.append(item+'\t'+ strpage + '\n') elif (item == 2): imgname = scribus.getImageFile(item) T.append(item+' ' + imgname + '\t' + strpage + '\n') page +=1 output_file = open(textfile,'w') output_file.writelines(T) output_file.close() endmessage = textfile + ' was created' scribus.messageBox("Finished", endmessage, scribus.ICON_NONE, scribus.BUTTON_OK) if scribus.haveDoc(): textfile = scribus.fileDialog('Enter name of file to save to', filter='Text Files (*.txt);;All Files (*)') try: if textfile == '': raise Exception exportText(textfile) except Exception, e: print e else: scribus.messageBox('Usage Error', 'You need a Document open', scribus.ICON_NONE, scribus.BUTTON_OK)