| View previous topic :: View next topic |
| Author |
Message |
ms777 Super User


Joined: 07 Feb 2004 Posts: 1355
|
Posted: Thu Sep 01, 2005 1:47 am Post subject: Using Xray from Beanshell |
|
|
Recently I started to (try to) program some scripts in Beanshell. As an old Basic programmer, I immediately missed the great functionality of B Marcelly's Xray tool. The below Beanshell code shows, how to call Xray from a Beanshell script. Run this with an open writer document.
| Code: | import com.sun.star.uno.UnoRuntime;
import com.sun.star.uno.XComponentContext;
import com.sun.star.frame.XDesktop;
import com.sun.star.frame.XModel;
import drafts.com.sun.star.script.provider.XScriptContext;
xCompCont = XSCRIPTCONTEXT.getComponentContext();
xMultiComponentFactory = xCompCont.getServiceManager();
//----------------------------- XRay-specific initializations and function definitions / start -----------
import com.sun.star.script.provider.XScriptProviderFactory;
import com.sun.star.script.provider.XScriptProvider;
Object oMSPFac = xMultiComponentFactory.createInstanceWithContext( "com.sun.star.script.provider.MasterScriptProviderFactory", xCompCont);
xScriptProviderFactory = (XScriptProviderFactory) UnoRuntime.queryInterface(XScriptProviderFactory.class, oMSPFac);
Object oMSP = xScriptProviderFactory.createScriptProvider("");
xScriptProvider = (XScriptProvider) UnoRuntime.queryInterface(XScriptProvider.class, oMSP);
oXrayScript = xScriptProvider.getScript("vnd.sun.star.script:Xray._Main.Xray?language=Basic&location=application");
public void XrayBSH(Object oXrayScript, Object oObj) {
Object ObjArrayIn = new Object[ 1 ];
ObjArrayIn[0] = oObj;
Object a;
Object b;
oXrayScript.invoke(ObjArrayIn, a, b);
}
//----------------------------- XRay-specific initializations and function definitions / end ---------
//----------------------------- now you can use the following command to XRay your Object oObj ---------
//----------------------------- XrayBSH(oXrayScript, oObj);
import com.sun.star.text.XTextDocument;
import com.sun.star.text.XText;
import com.sun.star.text.XTextRange;
import com.sun.star.text.XTextCursor;
oDoc = XSCRIPTCONTEXT.getDocument();
xTextDoc = (XTextDocument) UnoRuntime.queryInterface(XTextDocument.class,oDoc);
xText = xTextDoc.getText();
xText.setString("");
xTextCursor = xText.createTextCursor();
xText.insertString(xTextCursor, "Some Text in the first line\n", false);
xText.insertString(xTextCursor, "Some Text in the second line\n", false);
XrayBSH(oXrayScript, xTextCursor);
return 0;
|
|
|
| Back to top |
|
 |
B Marcelly Super User

Joined: 12 May 2004 Posts: 1414 Location: France
|
Posted: Thu Sep 01, 2005 4:05 am Post subject: |
|
|
| Quote: | | The below Beanshell code shows, how to call Xray from a Beanshell script. |
Fantastic code I made it work without a hitch.
Perhaps it is possible to do the equivalent in Python or even C++ (look, SergeM!)
Exchanging objects between scripts opens up lots of possibilities. Thanks a lot
______
Bernard |
|
| Back to top |
|
 |
SergeM Super User

Joined: 09 Sep 2003 Posts: 3211 Location: Troyes France
|
|
| Back to top |
|
 |
hol.sten Super User


Joined: 14 Nov 2004 Posts: 3532 Location: Hamburg, Germany
|
Posted: Sat Mar 08, 2008 9:59 am Post subject: |
|
|
| B Marcelly wrote: | | Quote: | | The below Beanshell code shows, how to call Xray from a Beanshell script. |
Fantastic code I made it work without a hitch. |
I gave Xray my first try today. And the above posted code didn't work. I got it running with Xray 5.2, OOo 2.3.1 on Windows XP after I changed the line | Code: | | oXrayScript = xScriptProvider.getScript("vnd.sun.star.script:Xray._Main.Xray?language=Basic&location=application"); | to | Code: | | oXrayScript = xScriptProvider.getScript("vnd.sun.star.script:XrayTool._Main.Xray?language=Basic&location=application"); | . |
|
| Back to top |
|
 |
B Marcelly Super User

Joined: 12 May 2004 Posts: 1414 Location: France
|
Posted: Sat Mar 08, 2008 11:18 am Post subject: |
|
|
| hol.sten wrote: | I gave Xray my first try today. And the above posted code didn't work. I got it running with Xray 5.2, OOo 2.3.1 on Windows XP after I changed the line | Code: | | oXrayScript = xScriptProvider.getScript("vnd.sun.star.script:Xray._Main.Xray?language=Basic&location=application"); | to | Code: | | oXrayScript = xScriptProvider.getScript("vnd.sun.star.script:XrayTool._Main.Xray?language=Basic&location=application"); | . |
FYI, read Xray documentation, chapter 4.2. There is a code to call Xray from Beanshell
______
Bernard |
|
| Back to top |
|
 |
hol.sten Super User


Joined: 14 Nov 2004 Posts: 3532 Location: Hamburg, Germany
|
Posted: Sat Mar 08, 2008 11:30 am Post subject: |
|
|
| B Marcelly wrote: | | hol.sten wrote: | I gave Xray my first try today. And the above posted code didn't work. I got it running with Xray 5.2, OOo 2.3.1 on Windows XP after I changed the line | Code: | | oXrayScript = xScriptProvider.getScript("vnd.sun.star.script:Xray._Main.Xray?language=Basic&location=application"); | to | Code: | | oXrayScript = xScriptProvider.getScript("vnd.sun.star.script:XrayTool._Main.Xray?language=Basic&location=application"); | . |
FYI, read Xray documentation, chapter 4.2. There is a code to call Xray from Beanshell  |
Yes, I already found that. But I was puzzled why the example in chapter 4.2 workd for me, but the above didn't. Finally all I did was posting what I changed in the above code to get it working. |
|
| Back to top |
|
 |
B Marcelly Super User

Joined: 12 May 2004 Posts: 1414 Location: France
|
Posted: Sat Mar 08, 2008 11:38 pm Post subject: |
|
|
| Quote: | | I was puzzled why the example in chapter 4.2 workd for me, but the above didn't. |
ms777 was correct with version 4 of Xray.
The library name was changed from Xray to XrayTool with version 5 of Xray.
______
Bernard |
|
| Back to top |
|
 |
|