Ask Your Question
0

UNO: iterate over objects in Impress slides

asked 2019-07-17 04:13:01 +0200

Hi-Angel gravatar image

How to iterate over objects inside slides, such as e.g. images, tables, etc?

For example, the code below connects to Impress, and retrieves 1st slide. But, how do I e.g. get images on this page?

#!python
import uno

# run libreoffice as:
# soffice --calc --accept="socket,host=localhost,port=2002;urp;StarOffice.ServiceManager"

def connectToLO():
    # get the uno component context from the PyUNO runtime
    localContext = uno.getComponentContext()
    resolver = localContext.ServiceManager.createInstanceWithContext(
        "com.sun.star.bridge.UnoUrlResolver", localContext )
    # connect to the running office
    ctx = resolver.resolve( "uno:socket,host=localhost,port=2002;urp;StarOffice.ComponentContext" )
    smgr = ctx.ServiceManager
    desktop = smgr.createInstanceWithContext( "com.sun.star.frame.Desktop",ctx)
    return desktop.CurrentComponent

model = connectToLO()
slide1 = model.DrawPages.getByIndex(0)
print(slide1.Name)
edit retag flag offensive close merge delete

1 Answer

Sort by » oldest newest most voted
1

answered 2019-07-17 04:46:46 +0200

updated 2019-07-17 04:48:17 +0200

The document should implement com.sun.star.drawing.XDrawPagesSupplier interface. It allows to get access to com.sun.star.drawing.XDrawPages; the latter gives indexed access to individual com.sun.star.drawing.XDrawPage; and that interface gives indexed access to individual shapes.

So in essence, you get access to elements on the slide1 using

slide1.getByIndex(n)
edit flag offensive delete link more

Comments

Anyway, I would suggest you to look at APSO extension (and the introspection tools mentioned there).

Mike Kaganski gravatar imageMike Kaganski ( 2019-07-17 07:13:35 +0200 )edit
Login/Signup to Answer

Question Tools

1 follower

Stats

Asked: 2019-07-17 04:13:01 +0200

Seen: 29 times

Last updated: Jul 17