FLOSS Manuals

 English |  Español |  Français |  Italiano |  Português |  Русский |  Shqip

Python Scripting with Scribus


Conceptually and in fact this is a simple script. You have some object on the page, and you want to create some guides that line up with the edges, so that you can create other content that also abuts one or more of these guides also.

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

# setguides2object.py
# Sets horizontal and vertical guides at the
# borders of a selected object
# preserves existing guides.

import scribus

if scribus.haveDoc():
        f = scribus.getSelectedObject()
        xpos, ypos = scribus.getPosition(f)
        width, height = scribus.getSize(f)
        scribus.setHGuides(scribus.getHGuides() + [ypos, ypos + height])
        scribus.setVGuides(scribus.getVGuides() + [xpos, xpos + width])
        result = scribus.messageBox('Error', 'You must select an object')

    result = scribus.messageBox('Error','You need a Document open')

We first check to see if an object is selected, then although we don't directly check if there is a selected object, we use try in a way that an error is generated if we can't getSelectedObject(). Once we get the position and size of the object we know where the guides should be.

Something you do need to know is that you can just add an individual guide. setHGuides() and setVGuides() require a list of all the guides you wish to have on the page, so you must get existing guides, presuming that you want to preserve those, then append any new guides.

There has been error in communication with Booktype server. Not sure right now where is the problem.

You should refresh this page.