Resize Objects: Difference between revisions
Line 73: | Line 73: | ||
</pre> | </pre> | ||
===resizeobject2.py=== |
Revision as of 16:05, 4 August 2012
Here is a script, (a pair of them really) that does something simple – alters the size of an object. This probably has some limited use, since it approaches the task by suggesting that you want to increase or decrease the size of an object by some mathematical factor. Yet, it still might get you somewhere in the ballpark, so that finer tuning is then possible by other means. You can also undo what you've done with this script, then run it again with a different factor, for another form of finetuning.
resizeobject.py
This first version asks for a single input for enlarging or shrinking. The default of 0.5 would halve the width and height. To double, enter 2. It seems to work on various kinds of frames, shapes, arcs, groups (a true group, not just a collection of selected objects), and even vector objects. Although it works on a spiral, there is a display problem after running the script, which seemingly can only be overcome by saving the file, closing, then reloading.
#!/usr/bin/env python # -*- coding: utf-8 -*- #resizeobject.py # **************************************************************************** # This program is free software; you can redistribute it and/or modify # it under the terms of the GNU General Public License as published by # the Free Software Foundation; either version 2 of the License, or # (at your option) any later version. # # This program is distributed in the hope that it will be useful, # but WITHOUT ANY WARRANTY; without even the implied warranty of # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the # GNU General Public License for more details. # # You should have received a copy of the GNU General Public License # along with this program; if not, write to the Free Software # Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. # # **************************************************************************** """ © 2012 by Gregory Pittman Select an object, start script. Enter a value to shrink/enlarge by, click Ok. """ try: 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." sys.exit(1) if not scribus.haveDoc(): scribus.messageBox('Scribus - Script Error', "No document open", scribus.ICON_WARNING, scribus.BUTTON_OK) sys.exit(1) if scribus.selectionCount() == 0: scribus.messageBox('Scribus - Script Error', "There is no object selected.\nPlease select a text frame 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 one text frame and try again.", scribus.ICON_WARNING, scribus.BUTTON_OK) sys.exit(2) selected_frame = scribus.getSelectedObject() pageitems = scribus.getPageItems() scribus.setRedraw(False) dimensions = scribus.getSize(selected_frame) # (width, height) factor = scribus.valueDialog("Resize Object", "Resize by multiple or decimal fraction", "0.5") factor = float(factor) newwidth = dimensions[0]*factor newheight = dimensions[1]*factor scribus.sizeObject(newwidth, newheight) scribus.setRedraw(True) scribus.redrawAll()