import uno def getModel(): # get the uno component context from the PyUNO runtime localContext = uno.getComponentContext() # create the UnoUrlResolver resolver = localContext.ServiceManager.createInstanceWithContext( "com.sun.star.bridge.UnoUrlResolver", localContext) # connect to the running office context = resolver.resolve("uno:socket,host=localhost,port=2002;urp;StarOffice.ComponentContext") manager = context.ServiceManager # get the central desktop object desktop = manager.createInstanceWithContext("com.sun.star.frame.Desktop", context) # access the current writer document return desktop.getCurrentComponent() def debug(msg): print(msg)