| View previous topic :: View next topic |
| Author |
Message |
accabrown Power User

Joined: 21 Apr 2004 Posts: 75 Location: England
|
Posted: Wed Aug 31, 2005 9:20 am Post subject: Calling python scripts from basic |
|
|
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 |
|
 |
ms777 Super User


Joined: 07 Feb 2004 Posts: 1355
|
Posted: Wed Aug 31, 2005 9:47 am Post subject: |
|
|
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 |
|
 |
accabrown Power User

Joined: 21 Apr 2004 Posts: 75 Location: England
|
Posted: Thu Sep 01, 2005 2:46 am Post subject: |
|
|
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 |
|
 |
accabrown Power User

Joined: 21 Apr 2004 Posts: 75 Location: England
|
Posted: Thu Sep 01, 2005 2:47 am Post subject: |
|
|
| one minor point: "Python" has to be in title case. |
|
| Back to top |
|
 |
ms777 Super User


Joined: 07 Feb 2004 Posts: 1355
|
|
| Back to top |
|
 |
ms777 Super User


Joined: 07 Feb 2004 Posts: 1355
|
Posted: Thu Sep 01, 2005 3:07 am Post subject: |
|
|
| 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 |
|
 |
accabrown Power User

Joined: 21 Apr 2004 Posts: 75 Location: England
|
Posted: Thu Sep 01, 2005 4:21 am Post subject: |
|
|
| 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 |
|
 |
lwhansen Newbie

Joined: 31 Jul 2008 Posts: 1
|
Posted: Thu Jul 31, 2008 9:21 am Post subject: |
|
|
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 |
|
 |
|