[scribus] PDFfile causes looping to fail?

Jerry Stratton scribusjerry at hoboes.com
Thu Feb 28 18:08:16 UTC 2019


On Feb 27, 2019, at 4:53 PM, ZASKE Martin <zm at revue-gugu.org> wrote:
> Again: If you want better bug-hunting, please provide a Scribus file and
> a real-life script and what you hope to see and then we can try on our
> machines.

Done. I’ve attached Pregens.sla, the document that exhibits this problem for me in Scribus 1.4.7 on macOS 10.14.3. For a testing script, the easiest one that generates the error for me is:

-----
import scribus
countDown = ['three', 'two', 'one']
scribus.PDFfile()
for counter in countDown:
	scribus.messageBox("Counter", counter)
-----

This allows you to see the script fail only at the end of the list; but if you’re worried about scribus.messageBox being part of the problem, replace that line with just “pass”.

The real-life script is this, which generates a PDF in the chosen folder for each layer except the background:

-----
#!/usr/bin/python
# -*- coding: utf-8 -*-

import scribus
import os

#don't do anything unless there's a document open
if scribus.haveDoc():
	#get the folder to save to
	saveTo = scribus.fileDialog('Folder to save characters to:', isdir=True, issave=True)

	if saveTo:
		#deselect, or it will only print the current selection
		scribus.deselectAll()
		layers = scribus.getLayers()
		
		#first, make sure only the background is set to print
		for layer in layers:
			if layer == 'Background':
				scribus.setLayerPrintable(layer, True)
			else:
				scribus.setLayerPrintable(layer, False)

		#now, go through each non-background layer and export as PDF
		exporter = scribus.PDFfile()
		for layer in layers:
			if layer != 'Background':
				scribus.setLayerPrintable(layer, True)
				filePath = os.path.join(saveTo, layer + '.pdf')
				#filePath = saveTo + '/' + layer + '.pdf'
				exporter.file = filePath
				exporter.save()
				scribus.setLayerPrintable(layer, False)

else:
	scribus.messageBox("No Open Document", "You need to have a document open to save it as PDF.")
-----

It fails (for me) with the same error—list assignment out of range—in this case when attempting os.path.join. If os.path.join is commented out and the line below it using simple string concatenation uncommented, the error will appear at the end of looping through the layers, after the PDF files are created.

Traceback (most recent call last):
 File "<string>", line 8, in <module>
 File "/Users/jerry/bin/Scribus/printLayers.py", line 29, in <module>
   filePath = os.path.join(saveTo, layer + '.pdf')
 File "/System/Library/Frameworks/Python.framework/Versions/2.5/lib/python2.7/posixpath.py", line 67, in join
   for b in p:
IndexError: list assignment index out of range

-------------- next part --------------
A non-text attachment was scrubbed...
Name: Pregens.sla.zip
Type: application/zip
Size: 24473 bytes
Desc: not available
URL: <http://lists.scribus.net/pipermail/scribus/attachments/20190228/5b6a8995/attachment.zip>
-------------- next part --------------


Jerry


More information about the scribus mailing list