CopyObject() and pasteObject(): Difference between revisions

From Scribus Wiki
Jump to navigation Jump to search
No edit summary
No edit summary
Line 3: Line 3:


Eventually, I plan to write a more flexible script, but initially, the script below uses these commands to copy a selected object to all pages, odd pages, or even pages. If you specify anything else, nothing happens.
Eventually, I plan to write a more flexible script, but initially, the script below uses these commands to copy a selected object to all pages, odd pages, or even pages. If you specify anything else, nothing happens.
===DIY==
===DIY===
As of this writing, these commands are not yet available in Scripter.
As of this writing, these commands are not yet available in Scripter.
For the brave, or at least those who understand something about svn a building scribus:
For the brave, or at least those who understand something about svn a building scribus:
Line 11: Line 11:
Download the file ''cmdobj.tar''.
Download the file ''cmdobj.tar''.
Untar this file with <tt>tar xvf cmdobj.tar</tt>
Untar this file with <tt>tar xvf cmdobj.tar</tt>
Now you have a directory named '''scripter''', and inside you will find
<pre>
cmdobj.cpp
cmdobj.h
scriptplugin.cpp
scripterapi-manobj.html
</pre>
The first 3 files need to be copied to ''yoursvndir/scribus/plugin/scripter/''.
The last one goes to ''yoursvndir/scribus/doc/en/''.
Now you just ''cmake, make, make install'' as usual.
You can also download the ''paste2all.py'' script from the feature request to try out your new commands.


===paste2all.py===
===paste2all.py===

Revision as of 23:35, 22 March 2012

This article is part of the Scripts series.

This is an introduction to a couple of new Scripter commands. What these allow for is for the copying of selected objects (individually) to all or a number of pages. You might consider this as a workaround for the issue some have brought up regarding Master Pages, so that something occurring on a Master Page might be editable on individual pages.

Eventually, I plan to write a more flexible script, but initially, the script below uses these commands to copy a selected object to all pages, odd pages, or even pages. If you specify anything else, nothing happens.

DIY

As of this writing, these commands are not yet available in Scripter. For the brave, or at least those who understand something about svn a building scribus:

Go to: http://bugs.scribus.net/view.php?id=10560

Download the file cmdobj.tar. Untar this file with tar xvf cmdobj.tar Now you have a directory named scripter, and inside you will find

cmdobj.cpp
cmdobj.h
scriptplugin.cpp
scripterapi-manobj.html

The first 3 files need to be copied to yoursvndir/scribus/plugin/scripter/. The last one goes to yoursvndir/scribus/doc/en/.

Now you just cmake, make, make install as usual.

You can also download the paste2all.py script from the feature request to try out your new commands.

paste2all.py

#!/usr/bin/env python# -*- coding: utf-8 -*-
# File: paste2all.py# © 2012.01.29 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. Select a single object. Run the script, which asks whether you want
all, odd, or even pages to get a copy of the selected object (no copy is made to the original
page of the object). Any other input is ignored. When pasted, the copies go to the same page
coordinates of the original.

The script does not work with groups, and in fact Scribus will hang and then crash if you have
selected a group. If you select more than one item without grouping, an error is generated. This
isn't completely necessary, but otherwise only one object would be copied and pasted.

"""
import scribus
if scribus.haveDoc():
    if scribus.selectionCount() == 0:
        scribus.messageBox('Scribus - Usage Error',
                           "There is no object selected.\nPlease 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 only one object and try again.", scribus.ICON_WARNING, scribus.BUTTON_OK)
        sys.exit(2)
    paste2 = scribus.valueDialog('Paste to...',"Paste where?\n(all, odd, even)","all")
    selframe = scribus.getSelectedObject()
    pages = scribus.pageCount()
    currpage = scribus.currentPage()
    scribus.copyObject(selframe)
    if (paste2 == 'all'):
        i = 1
        while (i <= pages):
            if (i != currpage):
                scribus.gotoPage(i)
                scribus.pasteObject(selframe)
            i=i+1
    elif (paste2 == 'odd'):
        i = 1
        while (i <= pages):
            if (i != currpage):
                scribus.gotoPage(i)
                scribus.pasteObject(selframe)
            i=i+2
    elif (paste2 == 'even'):
        i = 2
        while (i <= pages):
            if (i != currpage):
                scribus.gotoPage(i)
                scribus.pasteObject(selframe)
            i=i+2
    scribus.setRedraw(1)
    scribus.docChanged(1)
    scribus.messageBox("Finished", "Done",icon=0,button1=1)
else:
    scribus.messageBox('Usage Error', 'You need a Document open', icon=0, button1=1)
    sys.exit(2)