[scribus] Getting a Text Frame's Page

Matt Miller matt.miller at fastmail.com
Thu Apr 14 01:35:35 UTC 2022


On Wed, Apr 13, 2022, at 17:11, Neil Foster wrote:
> I've solved many similar problems by parsing the document's .sla file
> (which is just XML), when the Scripter API doesn't quite do what you need.
>
> Here's the basic gist to get the page number for a frame named "foo":
>
> import xml.etree.ElementTree as ET
> tree = ET.parse(getDocName())
> root = tree.getroot()
> frame = "foo"
> element = root.find(f'./DOCUMENT/PAGEOBJECT[@ANNAME="{frame}"]')
> page_number = element.get("OwnPage")

That works great for me. Thanks.

> For this to work, the object has to manually have been given a name, not
> just leaving the auto-generated one, otherwise it's not stored in the .sla
> file.
>
> On Thu, 14 Apr 2022 at 00:43, Matt Miller <matt.miller at fastmail.com> wrote:
>
>> From Python I want to find the page number that contains a certain text
>> frame. I know the object name of the frame I'm looking for, but I don't
>> know what page it's on. The only way I've thought of is to loop
>> page-by-page over the document, and for each page use getAllObjects() to
>> see if the frame is on that page. The documents are typically hundreds or
>> even a couple thousand pages. I'm hoping for a faster way.
>>
>> From the GUI I see that if I click on an object to select it, then the
>> page returned by currentPage() is what I'm looking for, but if I just call
>> selectObject() then currentPage() doesn't seem to care.
>>
>> Thanks.
>>
>>
>> --
>>
>>   Matt Miller
>>   mailto:matt.miller at fastmail.com
>>
>> -------------- next part --------------
>> An HTML attachment was scrubbed...
>> URL: <
>> http://lists.scribus.net/pipermail/scribus/attachments/20220413/a7f1d8c6/attachment.htm
>> >
>> ___
>> Scribus Mailing List: scribus at lists.scribus.net
>> Edit your options or unsubscribe:
>> http://lists.scribus.net/mailman/listinfo/scribus
>> See also:
>> http://wiki.scribus.net
>> http://forums.scribus.net
>>
> -------------- next part --------------
> An HTML attachment was scrubbed...
> URL: 
> <http://lists.scribus.net/pipermail/scribus/attachments/20220414/d60ee11c/attachment.htm>
> ___
> Scribus Mailing List: scribus at lists.scribus.net
> Edit your options or unsubscribe:
> http://lists.scribus.net/mailman/listinfo/scribus
> See also:
> http://wiki.scribus.net
> http://forums.scribus.net

-- 

  Matt Miller
  mailto:matt.miller at fastmail.com



More information about the scribus mailing list