Enlarge2Page

From Scribus Wiki
Jump to: navigation, search
This article is part of the Scripts series.

This script takes a selected object, enlarges it to the page size, and places it at an X-Pos, Y-Pos of 0,0. Works for whatever units you are using, since it simply gets the information and uses your selected units.

There is error detection for no selected object, but also for more than one selected object. The script would actually work for more than one selected object, but the resizing/repositioning will only apply to one of them. If you have grouped objects no error is detected, but only the bounding box is affected – the items of the group are not changed in size or position. One warning: the basepoint needs to be in the upper left corner for positioning to work properly.

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

# Enlarge2Page.py
# this version 2011.03.26
# enlarges a selected object to the 
# size of the page
"""
Enlarge2Page.py

(c) 2011 Gregory Pittman 

A devilishly simple script (there are more lines for
detecting errors than for actually manipulating the
object) which enlarges a single selected object to 
size of the page and positions it at 0,0.

Assumes a basepoint in the upper left corner. Error detection
for no selected frame or more than one. Page units do not matter.

"""

import scribus

if scribus.haveDoc():
    if scribus.selectionCount() == 0:
        scribus.messageBox('Scribus - Script Error',
            "There is no object selected.\nPlease select one and try again.",
            scribus.ICON_WARNING, scribus.BUTTON_OK)
        sys.exit(2)
    if scribus.selectionCount() > 1:
        scribus.messageBox('Scribus - Script Error',
            "You have more than one object selected.\nPlease select only one and try again.",
            scribus.ICON_WARNING, scribus.BUTTON_OK)
        sys.exit(2)

    xdimension, ydimension = scribus.getPageSize()
    selectedframe = scribus.getSelectedObject()
    scribus.sizeObject(xdimension, ydimension, selectedframe)
    scribus.moveObjectAbs(0, 0, selectedframe)
    scribus.redrawAll()


Enlarge2Margins

But what if you want to enlarge to the margins instead, and you've already created an object, edited, and you don't want to start all over? Enlarge2Margins.py is your answer.

#!/usr/bin/env python
# -*- coding: utf-8  -*-
# Enlarge2Margins.py
# this version 2011.03.26
# enlarges a selected object to the 
# size of the margins

"""
Enlarge2Margins.py

(c) 2011 Gregory Pittman 

A devilishly simple script (there are more lines for
detecting errors than for actually manipulating the
object) which enlarges a single selected object to size 
of the margins and positions it appropriately.

Assumes a basepoint in the upper left corner. Error detection
for no selected frame or more than one. Page units do not matter.
"""
import scribus

if scribus.haveDoc():
    if scribus.selectionCount() == 0:
        scribus.messageBox('Scribus - Script Error',"There is no object selected.\nPlease select one and try again.",
             scribus.ICON_WARNING, scribus.BUTTON_OK)
        sys.exit(2)
    if scribus.selectionCount() > 1:
        scribus.messageBox('Scribus - Script Error',"You have more than one object selected.\nPlease select only one and try again.", 
             scribus.ICON_WARNING, scribus.BUTTON_OK)
        sys.exit(2)
    xdimension, ydimension = scribus.getPageSize()
    top,left,right,bottom = scribus.getPageMargins()
    selectedframe = scribus.getSelectedObject()
    scribus.sizeObject((xdimension - left - right), (ydimension - top - bottom), selectedframe)
    scribus.moveObjectAbs(left, top, selectedframe)
    scribus.redrawAll()

Enlarge2Page_v2.py

Of course we can combine the two and then have a script that lets us choose between page or margins. Also note that if you change your mind after you run the script, just run it again and change the choice.

#!/usr/bin/env python
# -*- coding: utf-8  -*-
# Enlarge2Page_v2.py
# this version 2011.03.26
# enlarges a selected object to the 
# size of the page

"""

Enlarge2Page_v2.py

(c) 2011 Gregory Pittman 

A simple script which enlarges a single selected object to size of the page or margins and positions it at the upper right
corner of the chosen feature.

Assumes a basepoint in the upper left corner. Error detection
for no selected frame or more than one. Page units do not matter.
"""

import scribus

if scribus.haveDoc():
    if scribus.selectionCount() == 0:
        scribus.messageBox('Scribus - Script Error',"There is no object selected.\nPlease select one and try again.",
             scribus.ICON_WARNING, scribus.BUTTON_OK)
        sys.exit(2)
    if scribus.selectionCount() > 1:
        scribus.messageBox('Scribus - Script Error',"You have more than one object selected.\nPlease select only one and try again.", 
             scribus.ICON_WARNING, scribus.BUTTON_OK)
        sys.exit(2)
    xdimension, ydimension = scribus.getPageSize()
    top,left,right,bottom = scribus.getPageMargins()
    selectedframe = scribus.getSelectedObject()
    enlargesize = scribus.valueDialog('Page or Margin?','Enlarge object to:\n(Anything other than default chooses margins)','page')
    if (enlargesize == 'page'):
        scribus.sizeObject(xdimension, ydimension, selectedframe)
        scribus.moveObjectAbs(0, 0, selectedframe)
    else:
        scribus.sizeObject((xdimension - left - right), (ydimension - top - bottom), selectedframe)
        scribus.moveObjectAbs(left, top, selectedframe)
    scribus.redrawAll()

Some Examples

These images are each of a full page (US Letter).

Enlarge.jpg Enlarge2.jpg Enlarge3.jpg Enlarge4.jpg
This first example is a simple one, enlarging a text frame to page size, then loading sample text to fill it, and making the text partially transparent, to use as a background. Again, rather simple, with two image frames, enlarged to page size, then Adjust Image to Frame, then Adjust Frame to Image. Then, by changing the basepoint I can determine the Y-Pos for one image to slide it down to the bottom of the page. This one isn't quite as simple as it looks. Start with a text frame, and put a single letter, enlarging just to see it well and picking a suitable font. Now, Convert to Outline, then Convert to Bezier, then run the script to enlarge to page. If you don't convert to Bezier the englargement will probably be disappointing. And finally, a slightly more complicated one than the last. This time the converted letter was enlarged to margins, then the letter rotated and shifted in X and Y positions to stay on the page. Then Convert to Polygon, so that I could Shape > Edit to change the foot of the R to bring it down to the bottom corner of the page. Then Convert to Image, load an image, resize and position.