Ask Your Question

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?

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(
        "", localContext )
    # connect to the running office
    ctx = resolver.resolve( "uno:socket,host=localhost,port=2002;urp;StarOffice.ComponentContext" )
    smgr = ctx.ServiceManager
    desktop = smgr.createInstanceWithContext( "",ctx)
    return desktop.CurrentComponent

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

1 Answer

Sort by » oldest newest most voted

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

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

The document should implement interface. It allows to get access to; the latter gives indexed access to individual; and that interface gives indexed access to individual shapes.

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

edit flag offensive delete link more


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


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

Seen: 29 times

Last updated: Jul 17