Re: Getting a Text Frame's Page
Craig Bradney <[email protected]> Thu, 14 Apr 2022 23:02:18 +0200
| Newsgroups | gmane.comp.graphics.scribus |
|---|---|
| Message-ID | <[email protected]> |
On 14/04/2022, 03:37, "Matt Miller" <[email protected]> wrote: 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 <[email protected]> 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. >> Hi I have now added a getItemPageNumber() scripter function in 1.5.9.svn and 1.7.0.svn. Thanks Craig ___ Scribus Mailing List: [email protected] Edit your options or unsubscribe: http://lists.scribus.net/mailman/listinfo/scribus See also: http://wiki.scribus.net http://forums.scribus.net