Difference between revisions of "Making Guides at an Object's Borders"

From Scribus Wiki
Jump to navigation Jump to search
Line 8: Line 8:
  
 
<pre>
 
<pre>
 +
#!/usr/bin/env python
 +
# -*- coding: utf-8 -*-
 +
# setguides2object.py (c)2011 Gregory Pittman
 +
# Sets horizontal and vertical guides at the
 +
# borders of a selected object
 +
# preserves existing guides.
 +
"""
 +
This is a simple script that creates horizontal
 +
and vertical guides at the edges of a selected object.
 +
As written, it only uses one object, and preserves
 +
any existing guides.
 +
"""
 +
import scribus
  
 +
if scribus.haveDoc():
 +
    try:
 +
        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])
 +
        scribus.setRedraw(1)
 +
    except:
 +
        result = scribus.messageBox('Error', 'You must select an object')
 +
        sys.exit(1)
 +
else:
 +
    result = scribus.messageBox('Error','You need a Document open')
 
</pre>
 
</pre>

Revision as of 15:09, 10 April 2011

This is a simple script whose idea comes from imagining that you have first created an object on the page and now you want to set some guides at the borders of the frame as a reference for other page content.

Usage is quite simple. Just select your object, run the script. Any pre-existing guides are preserved, so you can repeat this for other objects on the page. If there are any guides you don't want to keep, just slide them off the page – make sure your guides are not locked.

Create guides.png Create guides1.png

setguides2object.py

#!/usr/bin/env python
# -*- coding: utf-8 -*-
# setguides2object.py (c)2011 Gregory Pittman
# Sets horizontal and vertical guides at the 
# borders of a selected object
# preserves existing guides.
"""
This is a simple script that creates horizontal
and vertical guides at the edges of a selected object.
As written, it only uses one object, and preserves
any existing guides.
"""
import scribus

if scribus.haveDoc():
    try:
        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])
        scribus.setRedraw(1)
    except:
        result = scribus.messageBox('Error', 'You must select an object')
        sys.exit(1)
else:
    result = scribus.messageBox('Error','You need a Document open')