Author Topic: How to replace all frames in a page with another one  (Read 355 times)

Pumpkin

  • Newbie
  • *
  • Posts: 4
  • Karma: 0
  • Scribus User
How to replace all frames in a page with another one
« on: September 13, 2020, 03:59:23 pm »
I used scribus to make some figures composed of smaller ones like this:

SSSSSSSSSSSSSS
S
S
S
SSSSSSSSSSSSS
S
S
S
SSSSSSSSSSSSSS

The only difference is instead of letter S, I used small figures I drew with curves. Now I'd like to replace them all with another figure. In other words, I'd like to compose the bit letter E with a new figure but at the exact same locations. Is there anyway to do it quickly rather than manually compare the locate them?
Thank you!

Nermander

  • Hero Member
  • *****
  • Posts: 1379
  • Karma: 18
Re: How to replace all frames in a page with another one
« Reply #1 on: September 13, 2020, 04:51:36 pm »
It sounds as if the way you did it there is no easy way to do this.

I would maybe have tried to use pattern fill or maybe text on a path, but that means you should have done it from the start.

a.l.e

  • Global Moderator
  • Hero Member
  • *****
  • Posts: 2441
  • Karma: 35
    • the graphics lab
Re: How to replace all frames in a page with another one
« Reply #2 on: September 14, 2020, 10:38:25 am »
you can probably do that with a simple script.

if you want to really replace the drawings (and not create a second figure with a different drawing) you can use symbols (symbols are scrapbook elements that are linked to the original item)

a.l.e

  • Global Moderator
  • Hero Member
  • *****
  • Posts: 2441
  • Karma: 35
    • the graphics lab
Re: How to replace all frames in a page with another one
« Reply #3 on: September 14, 2020, 11:39:11 am »
this script does what you want:

- copy the new item
- select all the old items
- run the script

Code: [Select]
items = []
for i in range(n):
    items.append(scribus.getSelectedObject(i))

for item in items:
    pos = scribus.getPosition(item)
    dx, dy = pos
    scribus.pasteObject()
    new_item = scribus.getSelectedObject()
    pos = scribus.getPosition(new_item)
    dx, dy = dx - pos[0], dy - pos[1]
    scribus.moveObject(dx, dy, new_item)
    scribus.deleteObject(item)

here is a downloadable version of a full script:

https://raw.githubusercontent.com/aoloe/scribus-script-collection/master/replace-all-selected-items.py/replace-all-selected-items.py

Pumpkin

  • Newbie
  • *
  • Posts: 4
  • Karma: 0
  • Scribus User
Re: How to replace all frames in a page with another one
« Reply #4 on: September 14, 2020, 05:16:05 pm »
Thank you so much! I'm new to Scribus and have never thought of using scripts to do anything. I need to take a look at how to use it but thank you so much for the script!

Pumpkin

  • Newbie
  • *
  • Posts: 4
  • Karma: 0
  • Scribus User
Re: How to replace all frames in a page with another one
« Reply #5 on: September 14, 2020, 06:39:21 pm »
this script does what you want:

- copy the new item
- select all the old items
- run the script

Code: [Select]
items = []
for i in range(n):
    items.append(scribus.getSelectedObject(i))

for item in items:
    pos = scribus.getPosition(item)
    dx, dy = pos
    scribus.pasteObject()
    new_item = scribus.getSelectedObject()
    pos = scribus.getPosition(new_item)
    dx, dy = dx - pos[0], dy - pos[1]
    scribus.moveObject(dx, dy, new_item)
    scribus.deleteObject(item)

here is a downloadable version of a full script:

https://raw.githubusercontent.com/aoloe/scribus-script-collection/master/replace-all-selected-items.py/replace-all-selected-items.py




Hi a.l.e, I tried run the script the way you said, and there is an error message said 'module' object has no attribute 'pastObject'. Do you have any idea what could be the reason?
Thank you!

a.l.e

  • Global Moderator
  • Hero Member
  • *****
  • Posts: 2441
  • Karma: 35
    • the graphics lab
Re: How to replace all frames in a page with another one
« Reply #6 on: September 14, 2020, 06:48:58 pm »
yes, you probably need scribus 1.5.5 or 1.5.6svn for pasteObject().

1.5 versions are mostly compatible with each other.

but you cannot edit with scribus 1.4 documents that you have modified with scribus 1.5...

Pumpkin

  • Newbie
  • *
  • Posts: 4
  • Karma: 0
  • Scribus User
Re: How to replace all frames in a page with another one
« Reply #7 on: September 14, 2020, 07:43:46 pm »
yes, you probably need scribus 1.5.5 or 1.5.6svn for pasteObject().

1.5 versions are mostly compatible with each other.

but you cannot edit with scribus 1.4 documents that you have modified with scribus 1.5...



It worked perfectly! Thank you so much!!!