Hi,

[sorry if arrives twice, but I forgot to subscribe]

I'm facing some serious problems when trying to use the ScannerManager
service from a BeanShell script (inside OOo Draw).

OOo version: stable, 2.0.4 (english version, WinXP SP2)
OOo SDK: stable, 2.0.4

I have a Logitech QuickCam Sphere webcam (driver version 9.5). As I
acquire an image from Insert/Picture/Scan/Request, the image is taken
and inserted into the drawing.

What I want is to replace an image object (having name prefix of
"photofield_") in my OOo draw document in script-runtime.

The script I wrote is attached, but it does not work.

As I open a draw that have an image object named like "photofield_" and
try to run the script, I can select the source
(xScannerManager.configureScanner(...)). After the selection is made,
the startScan(...) call makes OOo to hang up.

It can be killed using the task manager, but after restarting OOo (but
not the OS), the menu-path (Insert/Picture/Scan/Request) also does not work.

Maybe I'm doing sg. the wrong way, or the webcam driver may be buggy
(driver update to v10 did not solve the problem).
Could someone point me to the right direction? Or could you give me some
eorking example using the com.sun.star.scanner.ScannerManager service?

Thanks in advance,

Josi

/*
    Import standard OpenOffice.org API classes. For more information on
    these classes and the OpenOffice.org API, see the OpenOffice.org
    Developers Guide at:

    http://api.openoffice.org/
*/

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 XScriptContext class. An instance of this class is available
    to all BeanShell scripts in the global variable "XSCRIPTCONTEXT". This
    variable can be used to access the document for which this script
    was invoked.

    Methods available are: 

        XSCRIPTCONTEXT.getDocument() returns XModel
        XSCRIPTCONTEXT.getDesktop() returns XDesktop
        XSCRIPTCONTEXT.getComponentContext() returns XComponentContext

    For more information on using this class see the scripting
    developer guides at:

        http://framework.openoffice.org/scripting/index.html
*/
        
import drafts.com.sun.star.script.provider.XScriptContext;

//PatronCard creator in BeanShell
// somewhat messy import section
import com.sun.star.beans.XPropertySet;
import com.sun.star.uno.AnyConverter;
import com.sun.star.lang.XMultiComponentFactory;
import com.sun.star.lang.XEventListener;
import com.sun.star.frame.XDispatchHelper;

import com.sun.star.container.XIndexAccess;
import com.sun.star.container.XNamed;

import com.sun.star.drawing.XDrawPagesSupplier;
import com.sun.star.drawing.XDrawPages;
import com.sun.star.drawing.XDrawPage;
import com.sun.star.drawing.XShape;
import com.sun.star.drawing.XShapes;

import com.sun.star.scanner.XScannerManager;
import com.sun.star.scanner.ScannerManager;
import com.sun.star.scanner.ScannerContext;

import com.sun.star.text.XText;
import com.sun.star.text.XTextCursor;

// get the document context
oDoc = XSCRIPTCONTEXT.getDocument();


xDrawingDoc = (XDrawPagesSupplier) 
UnoRuntime.queryInterface(XDrawPagesSupplier.class, oDoc);

// retrieve the pages present in the document
xDrawPages = xDrawingDoc.getDrawPages();


// retrieve page with index 0
drawPage = xDrawPages.getByIndex(0);
xDrawPage = (XDrawPage) UnoRuntime.queryInterface(XDrawPage.class, drawPage);

// get the shapes from the page
xShapes = (XShapes) UnoRuntime.queryInterface(XShapes.class, xDrawPage);
xIndexedShapes=(XIndexAccess) UnoRuntime.queryInterface(XIndexAccess.class, 
xShapes);

// iterate throug the shapes
for (int i=0; i<xIndexedShapes.getCount(); i++) {
        shape = xIndexedShapes.getByIndex(i);
        xShape = (XShape) UnoRuntime.queryInterface(XShape.class, shape);
        xNamedShape = (XNamed) UnoRuntime.queryInterface(XNamed.class, xShape);

        // see if we've found target object for a photo
        if (xNamedShape.getName().toLowerCase().indexOf("photofield_")==0) {
                XPropertySet xShapeProperties = (XPropertySet) 
UnoRuntime.queryInterface(XPropertySet.class, xShape);
                xText = (XText) UnoRuntime.queryInterface(XText.class, xShape);
                xTextCursor = xText.createTextCursor();
//              xTextCursor.setString("test string 1." + (new 
Date().toString()));

                // try creating a scanner service class
                oScannerM = new java.lang.Object();
                try {
                        oCompContext = XSCRIPTCONTEXT.getComponentContext();
                        xCompContext = (XComponentContext) 
UnoRuntime.queryInterface(XComponentContext.class, oCompContext);
                        oMCF = xCompContext.getServiceManager();
                        xMCF = (XMultiComponentFactory) 
UnoRuntime.queryInterface(XMultiComponentFactory.class, oMCF);
                        
oScannerM=xMCF.createInstanceWithContext("com.sun.star.scanner.ScannerManager", 
XSCRIPTCONTEXT.getComponentContext());
                        xScannerManager = (XScannerManager) 
UnoRuntime.queryInterface(XScannerManager.class, oScannerM);

                        // now we have a ScannerManager of type XScannerManager

                        if (xScannerManager != null ) {
                                scannerC = 
xScannerManager.getAvailableScanners();

                                // pop up config UI to select and configure the 
scanner
                                if (xScannerManager.configureScanner(scannerC)) 
{
                                // the choice was accepted.
//                                      xTextCursor.setString("the choice was 
accepted." + (new Date().toString()));
                                        xScannerManager.startScan(scannerC[0], 
new XEventListener() {
                                                public void disposing 
(com.sun.star.lang.EventObject e) { return; }
                                        });
//                                      xTextCursor.setString("teststring 3.");

                                } else {
                                        xTextCursor.setString("test string 4" + 
(new Date().toString()));
                                }

                        }
                } catch (java.lang.Exception e) {
//                      System.err.println("Error getting scanner: 
"+e.toString());
                        return -1;
                }


        }
}

// BeanShell OpenOffice.org scripts should always return 0
return 0;


---------------------------------------------------------------------
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]

Reply via email to