Scribus Forums

Scribus => Layout Issues => Topic started by: AliasHannibal on August 27, 2018, 04:08:29 PM

Title: Resize multiple text frames simultaneously
Post by: AliasHannibal on August 27, 2018, 04:08:29 PM
As a regular user of Scribus (I've typeset several books, and designed book covers, etc), I sometimes realize that I need to resize several text frames after I've created the document.

To do this I have to go to each frame and copy and paste (or type, but that's slower) the exact measures for the text frames. When I need to do this for a whole book (more than let's say 30 pages, but I often work with books of more than 200 pages), it is a hopeless job that takes forever. And since it could be automated, I wonder if there's a better way to do this.

I can create new documents and let Scribus automatically create text frames for me, but if I've already worked on several other features in this document, this becomes less attractive as an option.

If I try and zoom out and select all the text frames, I have found that the text frames behave erratically. Sometimes they resize unevenly, or in proportion to each other. This is not what I want. I want to change all of them at the same time to the same measurements.

Is there any other way to change the size simultaneously? Thanks in advance.
Title: Re: Resize multiple text frames simultaneously
Post by: Nermander on August 27, 2018, 04:58:02 PM
I'd say the best way is probably to write a script for it.

I don't think it would be very hard to write a script that does "Every frame with these measures shall be changed to this size". A loop and a couple of if statements.
Title: Re: Resize multiple text frames simultaneously
Post by: AliasHannibal on August 27, 2018, 05:08:39 PM
Thanks for the quick reply.

That would be great. I know nothing about how to do that. Do you?
Title: Re: Resize multiple text frames simultaneously
Post by: Nermander on August 27, 2018, 07:54:23 PM
I have not yet bothered to learn the Scribus scripter, but I think there is already a sample script out there that iterates through all text frames in the document. I would think it is not very complicated to adjust it with a few if statements, at least if you know a little about programming.
Title: Re: Resize multiple text frames simultaneously
Post by: AliasHannibal on August 27, 2018, 08:02:40 PM
Sorry. I don't. I am hopeless with any sort of programming. But I really appreciate you guiding me in the right direction. Thanks.
Title: Re: Resize multiple text frames simultaneously
Post by: Ewac on June 16, 2021, 06:30:49 AM
Has there been a solution to this issue in the past years? I'm in the same situation and would really appreciate a way to rezise multiple frames together....
Title: Re: Resize multiple text frames simultaneously
Post by: RobSay on June 16, 2021, 07:29:19 PM
I'm not aware of any new solutions to this and I use scripter to achieve a similar sort of effect (standard width image frames over 250 pages)

For a straight forward resize of all frames within the whole document - you can run this in the scripter console:

# select all the items in the document - you can be much cleverer than this with page ranges etc
allItems = getAllObjects()
# loop through all the objects
for item in allItems :
  # look for text frames only - you can be cleverer here in lots of ways and filter by type, name, property .. whatever
  if (getObjectType(item) == 'TextFrame'):
    # set the frame dimensions (you can calculate the desired width and height etc)
    sizeObject(200,30, item)
    # you could also move the text frame to a specific point on the page (might need to check the current page)
    # moveObjectAbs(x,y,item)

Title: Re: Resize multiple text frames simultaneously
Post by: Ewac on August 10, 2021, 03:19:25 PM
I have tried this unsuccesfully, but I never worked with scrips ever and I am not even sure how to fill out the template you gave exactly. I have 300+ pages and need to change all the frames now.
If it's not too much to ask, could you show me how I have to adjuct the template script to change
every text frame in the document
to the size w 122mm, h 190mm
in the position x 10mm, y 10mm
Title: Re: Resize multiple text frames simultaneously
Post by: RobSay on August 12, 2021, 12:36:56 AM
Scripter can be a little finicky - but it is very powerful.

Try this:
The text frame you created in step 1 and the text frame on the 2nd page should be resized to your dimensions and position (assuming your default doc is defined in mm).

If it's doing what you want ... open your 300 page document and repeat steps 3 & 4.


pageNum = 1
totalPageCount = pageCount()
while (pageNum <= totalPageCount):
  gotoPage(pageNum)
  # select all text frame items on the current page
  allItems = getAllObjects(ITEMTYPE_TEXTFRAME)
  # loop through all the objects
  for item in allItems :
    sizeObject(122,190, item)
    moveObjectAbs(10,10,item)
  # next page
  pageNum +=1
# leave a blank line at the end for the scripter console - after this comment


The final blank line is critical - as is all of the indentation (spaces not tabs)
Title: Re: Resize multiple text frames simultaneously
Post by: AdmFubar on August 12, 2021, 06:03:46 AM
While not an immediate solution, what seems to be a better option would be styles for images. This would allow changing the frame sizing, location, etc. . would be usfull for other objects as well.
Title: Re: Resize multiple text frames simultaneously
Post by: Thiago David on May 31, 2022, 05:56:31 PM
Hi, here is a solution I found today
I'm not a programmer so this code can be optimized

Go to Script menu> console> paste the code below and change the numbers

page = 2                                                   #Click on your first text box and you will find the number, in my case was Text2
pagenum = scribus.pageCount()
content = []

while (page <= pagenum):
scribus.gotoPage(page)
n = scribus.getPageItems()
for item in n:
selectObject("Text"+str(page))             #If you change the text box name then change here too
print "Text"+str(page)                     #Just to check if its working
scribus.sizeObject (W, H)                  #Change W to your width and H to your height
#scribus.moveObjectAbs (x, y)              #(Exemple)You can add other modifications too, just choose the function from the: Scribus' Automatic Scripter Commands list
deselectAll()
page +=1
                                                           #Let this last line blank to work
Title: Re: Resize multiple text frames simultaneously
Post by: Hakanost on January 25, 2023, 11:42:54 PM
I found this thread while looking for a solution to resize multiple objects to the same fixed values.
The scripts I could find all scaled the objects existing size by a percentage, not to a fixed value as I wanted.
I solved this by modifying an existing script by Alessandro Rimoldi.
https://wiki.scribus.net/canvas/Script_Resize_selected_objects (https://wiki.scribus.net/canvas/Script_Resize_selected_objects)


import sys
try:
   import scribus
except ImportError:
   print "This script only works from within Scribus"
   sys.exit(1)

n = scribus.selectionCount()

if n == 0 :
    scribus.messageBox('Error:', 'No frame selected');
    sys.exit(1)

w = int(scribus.valueDialog('Width', 'New width (in current unit)', '10'))
h = int(scribus.valueDialog('Height', 'New height (in current unit)', '10'))

for i in range(0, n):
    frame = scribus.getSelectedObject(i)
    scribus.sizeObject(w, h, frame)