How to pass an array of objects in python?

My ultimate goal is to insert an image in doc that is open in writer.

Right now I have the following code:

import Danny.OOo.OOoLib as OOoLib
import unohelper
import os.path
import glob
from import PropertyValue
from array import array

#dim args1(3) as new
#args1(0).Name = "FileName"
#args1(0).Value = "file://tesla/images/674.png"
#args1(1).Name = "FilterName"
#args1(1).Value = "<All formats>"
#args1(2).Name = "AsLink"
#args1(2).Value = false
#args1(3).Name = "Style"
#args1(3).Value = "Graphics"

L =  [ PropertyValue() for i in range(4)]

L[1].Value="<All formats>"
L[2].Name = "AsLink"
L[2].Value = False

desktop = OOoLib.getDesktop()
dispatcher = OOoLib.getServiceManager().createInstance('') 
dispatcher.executeDispatch(doc, ".uno:InsertGraphic", "", 0, L)

Open in new window

The executeDispatch call fails with the following error:

Traceback (most recent call last):
  File "", line 43, in ?
    dispatcher.executeDispatch(doc, ".uno:InsertGraphic", "", 0, L) exceptions.AttributeError: 'list' object has no attribute 'getTypes', traceback follows\nno traceback available

I think the problem is that I'm passing a python list when the called function is expecting the equivalent of a java array. How do I convert the list to something that has an attribute getTypes? Or do I need to create my own class and implement a getTypes method?
Who is Participating?
markoilicConnect With a Mentor Commented:

last line of your code should be

dispatcher.executeDispatch(doc.getCurrentController(), '.uno:InsertGraphic', '', 0, tuple(L))

and it will work
opikeAuthor Commented:
Thanks that got me past that issue but it's still not quite working yet. :) I'll open another thread for the new message.
Question has a verified solution.

Are you are experiencing a similar issue? Get a personalized answer when you ask a related question.

Have a better answer? Share it in a comment.

All Courses

From novice to tech pro — start learning today.