Author Topic: Creating an index with mulitple pages for the same topic (solved)  (Read 2234 times)


  • Newbie
  • *
  • Posts: 10
  • Karma: 0
  • Scribus User
In this forum, I posted a question on how to combine pages together to create an index like

Beef        5, 6
Chicken     3, 8

Scribus doesn't do this by default, so I created a script to do it. Maybe it can be useful to someone else too.

Code: [Select]
Allows you to create an index section. It will sort the entries and combine multiple pages
belonging to the same entry.

This allows you to have something like

Beef        5, 6
Chicken     3, 8

@author: Philippe Lavoie
@version: 1.0 / 20170125
@copyright (c) 2017 Philippe Lavoie under the mit license
@bugs the sort is a text sort, so 10 might come before 2. I'll fix that later.
import sys

import scribus
except ImportError:
print 'Unable to import the scribus module. This script will only run within'
print 'the Python interpreter embedded in Scribus. Try Script->Execute Script.'

if not  scribus.haveDoc():
scribus.messageBox('Error','You must have a document open',scribus.ICON_WARNING,scribus.BUTTON_OK)

if scribus.selectionCount() == 0:
scribus.messageBox('Scribus - Script Error','There is no object selected. Please select a text frame and try again.',scribus.ICON_WARNING, scribus.BUTTON_OK)

if scribus.selectionCount() > 1:  # get rid of or modify this section if you want more than one object selected
scribus.messageBox('Scribus - Script Error','You have more than one object selected. Please select one text frame and try again.', scribus.ICON_WARNING, scribus.BUTTON_OK)

lines = [s.split('\t') for s in scribus.getText().splitlines()]
newtext = ""

i = len(lines) - 1
page = lines[i][1]
while i>0 and (lines[i][0] == lines[i-1][0]):
page = lines[i-1][1] + ", " + page
i = i-1
newtext = entry + "\t" + page + "\n" + newtext
i = i-1