Calling a C++ function from Python

Java, C++, C#, Delphi... - Using the UNO bridges
Post Reply
saleem145
Posts: 130
Joined: Mon Jul 02, 2012 4:47 pm

Calling a C++ function from Python

Post by saleem145 »

Hello,

I am trying the following code --

Code: Select all

startDate = spreadsheet.NamedRanges.getByName("START_DATE").getReferredCells().getValue()
endDate = spreadsheet.NamedRanges.getByName("END_DATE").getReferredCells().getValue()
fields = spreadsheet.NamedRanges.getByName("FIELDS").getReferredCells().getDataArray()

service = CreateUnoService("my_module.MyService1")
service.initializeDataset(start_date, end_date, fields)
The last line is failing. Any suggestions. I have the code working from basic.

Thanks,

Saleem
OpenOffice 3.4.0
Mac OS X 10.5.8
User avatar
Charlie Young
Volunteer
Posts: 1559
Joined: Fri May 14, 2010 1:07 am

Re: Calling a C++ function from Python

Post by Charlie Young »

saleem145 wrote:Hello,

I am trying the following code --

Code: Select all

startDate = spreadsheet.NamedRanges.getByName("START_DATE").getReferredCells().getValue()
endDate = spreadsheet.NamedRanges.getByName("END_DATE").getReferredCells().getValue()
fields = spreadsheet.NamedRanges.getByName("FIELDS").getReferredCells().getDataArray()

service = CreateUnoService("my_module.MyService1")
service.initializeDataset(start_date, end_date, fields)
The last line is failing. Any suggestions. I have the code working from basic.

Thanks,

Saleem
createUnoService is a Basic function, not Python. It is equivalent to the ServiceManager's createInstance() method.

Try

Code: Select all

ctx = XSCRIPTCONTEXT.getComponentContext()
oMSF = ctx.getServiceManager()
oMSF.createInstance("some service")
Apache OpenOffice 4.1.1
Windows XP
saleem145
Posts: 130
Joined: Mon Jul 02, 2012 4:47 pm

Re: Calling a C++ function from Python

Post by saleem145 »

Hi Charlie,

That's not the issue. I have my own CreateUnoService implemented.

Code: Select all

def CreateUnoService(serviceName):

    sm = uno.getComponentContext().ServiceManager

    return sm.createInstanceWithContext(serviceName, uno.getComponentContext())
BTW: I got the plotting add-on to work.

Thanks,

Saleem
OpenOffice 3.4.0
Mac OS X 10.5.8
User avatar
Villeroy
Volunteer
Posts: 31363
Joined: Mon Oct 08, 2007 1:35 am
Location: Germany

Re: Calling a C++ function from Python

Post by Villeroy »

Why don't you use an object inspector?
Why don't you split up the long lines?

Code: Select all

onames = spreadsheet.NamedRanges
onamed = onames.getByName("START_DATE")

# this fails if the named has relative parts:
orange = onamed.getReferredCells()

# this fails because a range object has no value:
nval = orange.getValue()

ocell = orange.getCellByPosition(0,0)
nval = ocell.getValue()
Please, edit this topic's initial post and add "[Solved]" to the subject line if your problem has been solved.
Ubuntu 18.04 with LibreOffice 6.0, latest OpenOffice and LibreOffice
hanya
Volunteer
Posts: 885
Joined: Fri Nov 23, 2007 9:27 am
Location: Japan

Re: Calling a C++ function from Python

Post by hanya »

If you ask about your custom or own service, interface, structs or other API implementation, please write its IDL definitions. No one can understand or make answer without it.
Please, edit this thread's initial post and add "[Solved]" to the subject line if your problem has been solved.
Apache OpenOffice 4-dev on Xubuntu 14.04
Post Reply