Difference between revisions of "Creating an Object-sized Document"
|Line 62:||Line 62:|
Revision as of 14:07, 29 March 2017
Here is a small script based on a request from the mail list. What the poster wanted to know was whether there was a way to export a graphics frame to a file of some sort. Although you can export a document page as an image, this then requires some editing afterward. You could also use some type of screen grab software.
Another method would be to make a copy of the original object, create a new document the same size as the object, and then paste the object to it. This way, you could then either export to PDF or export as an image, with no need to trim the image later.
Here is a script that does this automatically, following these above steps, using copyObject() and pasteObject().
#!/usr/bin/env python # -*- coding: utf-8 -*- # File: object2doc.py - # © 2017.03.28 Gregory Pittman # 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. """ USAGE You must have a document open, and an object selected. The script copies the object, then creates a new single-page document having the width and height of the selected object. It then pastes the object to the new document, and moves it to the 0,0 position. """ import scribus if scribus.haveDoc(): c = 0 else: scribus.messageBox('Usage Error', 'You need a Document open', icon=0, button1=1) sys.exit(2) if scribus.selectionCount() == 0: scribus.messageBox('Scribus - Usage 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 - Usage 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) sel_obj = scribus.getSelectedObject() scribus.copyObject(sel_obj) units = scribus.getUnit() scribus.setUnit(scribus.UNIT_POINTS) objwidth, objheight = scribus.getSize(sel_obj) scribus.setUnit(units) scribus.newDocument((objwidth,objheight), (10,10,10,10),scribus.PORTRAIT,1,scribus.UNIT_POINTS,scribus.PAGE_1,0,1) scribus.pasteObject(sel_obj) scribus.moveObjectAbs(0,0,sel_obj) scribus.setRedraw(1) scribus.docChanged(1) scribus.messageBox("Finished", "Done!",scribus.ICON_NONE,scribus.BUTTON_OK)
One curious thing about this, seemingly related to the clipboard where the object is copied to, is that you can't repeat this process completely on another object in the same original document. The hitch comes up in the moveObjectAbs() command, which fails. This would add the one remaining manual step of setting the position of the pasted object at 0,0. If you load or create a new document, it will work, so perhaps you might delete the original, then reload it as a workaround, though this is more steps than just manually repositioning.
Incidentally, this seems to work not only on image frames, but any other sort of frame, including in imported SVG.