OpenOffice.org Forum at OOoForum.orgThe OpenOffice.org Forum
 
 [Home]   [FAQ]   [Search]   [Memberlist]   [Usergroups]   [Register
 [Profile]   [Log in to check your private messages]   [Log in

Calling python scripts from basic

 
Post new topic   Reply to topic    OOoForum.org Forum Index -> OpenOffice.org Macros and API
View previous topic :: View next topic  
Author Message
accabrown
Power User
Power User


Joined: 21 Apr 2004
Posts: 75
Location: England

PostPosted: Wed Aug 31, 2005 9:20 am    Post subject: Calling python scripts from basic Reply with quote

Why doesn't this work?
Code:


Sub Main
opythonthing=thisComponent.getScriptProvider()
'Xray.Xray(opythonthing)
ascript=opythonthing.getScript("vnd.sun.star.script:dynamicDialog?language=python&location=user")
ascript.Invoke()
End Sub


Xray shows that opythonthing has a getScript method; but it gets no scripts. Under m125 o Windows, I get an error about an unsatisfied query for an interface of type XScriptProvider.
Back to top
View user's profile Send private message Visit poster's website
ms777
Super User
Super User


Joined: 07 Feb 2004
Posts: 1355

PostPosted: Wed Aug 31, 2005 9:47 am    Post subject: Reply with quote

see http://www.oooforum.org/forum/viewtopic.phtml?t=21564 :

if you want to run a script in MyMacro, you have to use the global script provider and location:user
Code:
'use this, if you install the JavaScript subroutine in My Macros.
'Then the Javascript routine is available in all documents
'
oMasterScriptProviderFactory = createUnoService("com.sun.star.script.provider.MasterScriptProviderFactory")
oMasterScriptProvider = oMasterScriptProviderFactory.createScriptProvider("")
oScriptReplace = oMasterScriptProvider.getScript("vnd.sun.star.script:Tools.Replace.js?language=JavaScript&location=user")


if your python is in the document, take
Code:
'use this, if you install the JavaScript locally in the current doc
'
'oDocScriptProvider = ThisComponent.getScriptProvider()
'oScriptReplace = oDocScriptProvider.getScript("vnd.sun.star.script:Library1.Replace.js?language=JavaScript&location=document")


ThisComponent.getScriptprovider() and location=user are a contradiction

Good luck,

ms777
Back to top
View user's profile Send private message
accabrown
Power User
Power User


Joined: 21 Apr 2004
Posts: 75
Location: England

PostPosted: Thu Sep 01, 2005 2:46 am    Post subject: Reply with quote

Ah. This sort of works.

Testing it with the supplied Python example gives me a new error

Code:

Sub Main
oMasterScriptProviderFactory = createUnoService("com.sun.star.script.provider.MasterScriptProviderFactory")
oMasterScriptProvider = oMasterScriptProviderFactory.createScriptProvider("")
opythonthing=oMasterScriptProvider.getScript("vnd.sun.star.script:dynamicDialog.createDialog?language=Python&location=user")
Xray.Xray(opythonthing)
opythonthing.Invoke()
End Sub


Now I get a c.s.s.script.provider.ScriptFramerorkErrorException "an error ocurred during file opening"

gaaah
[/code]
Back to top
View user's profile Send private message Visit poster's website
accabrown
Power User
Power User


Joined: 21 Apr 2004
Posts: 75
Location: England

PostPosted: Thu Sep 01, 2005 2:47 am    Post subject: Reply with quote

one minor point: "Python" has to be in title case.
Back to top
View user's profile Send private message Visit poster's website
ms777
Super User
Super User


Joined: 07 Feb 2004
Posts: 1355

PostPosted: Thu Sep 01, 2005 3:05 am    Post subject: Reply with quote

In which line does the error occur ?

If it is the oMasterScriptProvider = ... line, try location=application rather than location=user. This seems not to be completely coherent between different scripting languages, see e.g. http://www.oooforum.org/forum/viewtopic.phtml?t=23333 for Beanshell

If it in the Invoke line, pass some parameters like in http://www.oooforum.org/forum/viewtopic.phtml?t=21564 , even if they are empty
Back to top
View user's profile Send private message
ms777
Super User
Super User


Joined: 07 Feb 2004
Posts: 1355

PostPosted: Thu Sep 01, 2005 3:07 am    Post subject: Reply with quote

One addition: c.s.s.script.provider.ScriptFramerorkErrorException "an error ocurred during file opening" does not necessarily mean, that something went wrong with invoking the script. If I remember correctly, you get the same error for an error within the script
Back to top
View user's profile Send private message
accabrown
Power User
Power User


Joined: 21 Apr 2004
Posts: 75
Location: England

PostPosted: Thu Sep 01, 2005 4:21 am    Post subject: Reply with quote

ms777 wrote:
In which line does the error occur ?

If it is the oMasterScriptProvider = ... line, try location=application rather than location=user.


It is in that line; but changing to locaiton=application gets me an error message that it can't find the Scripts directory in the main OOo tree, which is true, since it doesn't exist and I never created it.

The script runs perfectly well when called from the main organiser dialogue. So I don't think that this can be a script error.
Back to top
View user's profile Send private message Visit poster's website
lwhansen
Newbie
Newbie


Joined: 31 Jul 2008
Posts: 1

PostPosted: Thu Jul 31, 2008 9:21 am    Post subject: Reply with quote

I have been trying this as well. Turns out that you were very close. You have to specify the script and function slightly different for Python. Here it goes:

Code:
Sub CallPython
   oFactory = createUnoService("com.sun.star.script.provider.MasterScriptProviderFactory")
   oProvider = oFactory.createScriptProvider("")
   oScript = oProvider.getScript("vnd.sun.star.script:dynamicDialog.py$createDialog?language=Python&location=user")
   oScript.Invoke(Array(), Array(), Array())
end sub


This works!

Thanks for posting and good luck,
Lars
Back to top
View user's profile Send private message
Display posts from previous:   
Post new topic   Reply to topic    OOoForum.org Forum Index -> OpenOffice.org Macros and API All times are GMT - 8 Hours
Page 1 of 1

 
Jump to:  
You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum
You cannot vote in polls in this forum


Powered by phpBB © 2001, 2005 phpBB Group