ScriptForge.Session service

Session zerbitzuak xede orokorreko zenbait metodo biltzen ditu, honakoei lotutakoak:

Zerbitzuari deitzea

Basic lengoaian

    GlobalScope.BasicLibraries.LoadLibrary("ScriptForge")
    Dim session As Variant
    session = CreateScriptService("Session")
  
Python lengoaian

    from scriptforge import CreateScriptService
    session = CreateScriptService("Session")
  

Konstanteak

Below is a list of constants available to ease the designation of the library containing a Basic or Python script to invoke. Use them as session.CONSTANT.

CONSTANT

Balioa

Non dago liburutegia?

Aplikagarria

SCRIPTISEMBEDDED

"document"

dokumentuan

Basic + Python

SCRIPTISAPPLICATION

"application"

partekatutako edozein liburutegitan

Basic

SCRIPTISPERSONAL

"user"

Nire makroetan

Python

SCRIPTISPERSOXT

"user:uno_packages"

uneko erabiltzailearentzako instalatutako hedapen batean

Python

SCRIPTISSHARED

"share"

LibreOffice makroetan

Python

SCRIPTISSHAROXT

"share:uno_packages"

erabiltzaile guztientzat instalatutako hedapen batean

Python

SCRIPTISOXT

"uno_packages"

instalazio-parametro ezezagunak dituen hedapen batean

Python


Session zerbitzuaren metodoen zerrenda

ExecuteBasicScript
ExecuteCalcFunction
ExecutePythonScript
GetPDFExportOptions
HasUnoMethod

HasUnoProperty
OpenURLInBrowser
RunApplication
SendMail
SetPDFExportOptions

UnoMethods
UnoProperties
UnoObjectType
WebService


tip

Execute... methods in Session service behave as follows:
Arguments are passed by value. Changes made by the called function to the arguments do not update their values in the calling script.
A single value or an array of values is returned to the calling script.


ExecuteBasicScript

Exekutatu Basic scripta izena eta kokalekua emanda, eta atzitu emaitza, halakorik badago.

If the script returns nothing, which is the case of procedures defined with Sub, the returned value is Empty.

Sintaxia:

session.ExecuteBasicScript(scope: str, script: str, args: any[0..*]): any

Parametroak:

scope: String specifying where the script is stored. It can be either "document" (constant session.SCRIPTISEMBEDDED) or "application" (constant session.SCRIPTISAPPLICATION).

script: String specifying the script to be called in the format "library.module.method" as a case-sensitive string.

args: The arguments to be passed to the called script.

Adibidea:

Consider the following Basic function named DummyFunction that is stored in "My Macros" in the "Standard" library inside a module named "Module1".

The function simply takes in two integer values v1 and v2 and return the sum of all values starting in v1 and ending in v2.


    Function DummyFunction(v1 as Integer, v2 as Integer) As Long
        Dim result as Long, i as Integer
        For i = v1 To v2
            result = result + i
        Next i
        DummyFunction = result
    End Function
  

The examples below show how to call DummyFunction from within Basic and Python scripts.

Basic lengoaian

    Dim session : session = CreateScriptService("Session")
    Dim b_script as String, result as Long
    b_script = "Standard.Module1.DummyFunction"
    result = session.ExecuteBasicScript("application", b_script, 1, 10)
    MsgBox result ' 55
  
Python lengoaian

    session = CreateScriptService("Session")
    bas = CreateScriptService("Basic")
    b_script = 'Standard.Module1.DummyFunction'
    result = session.ExecuteBasicScript('application', b_script, 1, 10)
    bas.MsgBox(result) # 55
  

ExecuteCalcFunction

Exekutatu Calc funtzio bat bere ingelesezko izena erabilita eta emandako argumentuetan oinarrituta.
Argumentuak matrizeak badira, funtzioa matrize-formula modura exekutatuko da.

Sintaxia:

session.ExecuteCalcFunction(calcfunction: str, args: any[0..*]): any

Parametroak:

calcfunction: The name of the Calc function to be called, in English.

args: The arguments to be passed to the called Calc function. Each argument must be either a string, a numeric value or an array of arrays combining those types.

Adibidea:

Basic lengoaian

    session.ExecuteCalcFunction("AVERAGE", 1, 5, 3, 7) ' 4
    session.ExecuteCalcFunction("ABS", Array(Array(-1, 2, 3), Array(4, -5, 6), Array(7, 8, -9)))(2)(2) ' 9
    session.ExecuteCalcFunction("LN", -3)
    ' Errore bat sortzen du.
  
Python lengoaian

    session.ExecuteCalcFunction("AVERAGE", 1, 5, 3, 7) # 4
    session.ExecuteCalcFunction("ABS", ((-1, 2, 3), (4, -5, 6), (7, 8, -9)))[2][2] # 9
    session.ExecuteCalcFunction("LN", -3)
  

ExecutePythonScript

Exekutatu Python scripta, bere kokalekua eta izena emanda, eta atzitu emaitzak, halakorik badago. Emaitza balio bakarra edo balioen matrizea izan daiteke.

Scripta aurkitzen ez bada edo ezer ez bada itzultzen, itzulitako balioa Empty izango da.

LibreOffice Application Programming Interface (API) scriptgintzako lan-markoak lengoaien arteko scripten exekuzioa onartzen du Python eta Basic lengoaien kasuan, baina baita onartutako beste edozein programazio-lengoaiaren kasuan ere. Argumentuak atzera eta aurrera pasatu daitezke deietan, bi lengoaiek ezagutzen dituzten jatorrizko datu motak ordezkatzen badituzte, eta scriptgintzako lan-markoak haiek modu egokian bihurtuko dituztela onartuta.

Sintaxia:

session.ExecutePythonScript(scope: str, script: str, args: any[0..*]): any

Parametroak:

scope: One of the applicable constants listed above. The default value is session.SCRIPTISSHARED.

script: Either "library/module.py$method" or "module.py$method" or "myExtension.oxt|myScript|module.py$method" as a case-sensitive string.

args: The arguments to be passed to the called script.

Adibidea:

Consider the Python function odd_integers defined below that creates a list with odd integer values between v1 and v2. Suppose this function is stored in a file named my_macros.py in your user scripts folder.


    def odd_integers(v1, v2):
        odd_list = [v for v in range(v1, v2 + 1) if v % 2 != 0]
        return odd_list
  
tip

Read the help page Python Scripts Organization and Location to learn more about where Python scripts can be stored.


The following examples show how to call the function odd_integers from within Basic and Python scripts.

Basic lengoaian

    Dim script as String, session as Object
    script = "my_macros.py$odd_integers"
    session = CreateScriptService("Session")
    Dim result as Variant
    result = session.ExecutePythonScript(session.SCRIPTISPERSONAL, script, 1, 9)
    MsgBox SF_String.Represent(result)
  
Python lengoaian

    session = CreateScriptService("Session")
    script = "my_macros.py$odd_integers"
    result = session.ExecutePythonScript(session.SCRIPTISPERSONAL, script, 1, 9)
    bas.MsgBox(repr(result))
  

GetPDFExportOptions

Returns the current PDF export settings defined in the PDF Options dialog, which can be accessed by choosing File - Export as - Export as PDF.

Export options set with the PDF Options dialog are kept for future use. Hence GetPDFExportOptions returns the settings currently defined. In addition, use SetPDFExportOptions to change current PDF export options.

This method returns a Dictionary object wherein each key represent export options and the corresponding values are the current PDF export settings.

tip

Read the PDF Export wiki page to learn more about all available options.


Sintaxia:

session.GetPDFExportOptions(): obj

Adibidea:

Basic lengoaian

    Dim expSettings As Object, msg As String, key As String, optLabels As Variant
    expSettings = session.GetPDFExportOptions()
    optLabels = expSettings.Keys
    For Each key in optLabels
        msg = msg + key & ": " & expSettings.Item(key) & Chr(10)
    Next key
    MsgBox msg
    ' Zoom: 100
    ' Changes: 4
    ' Quality: 90
    ' ...
  
note

Metodo hau Basic scriptetan soilik dago erabilgarri.


HasUnoMethod

True itzultzen du UNO objektu batek metodoa badauka. False itzultzen du metodoa aurkitzen ez bada edo argumentu bat baliogabea bada.

Sintaxia:

session.HasUnoMethod(unoobject: uno, methodname: str): bool

Parametroak:

unoobject: The object to inspect.

methodname: the method as a case-sensitive string

Adibidea:

Basic lengoaian

    Dim a As Variant
    a = CreateUnoService("com.sun.star.sheet.FunctionAccess")
    MsgBox session.HasUnoMethod(a, "callFunction") ' True
  
Python lengoaian

    bas = CreateScriptService("Basic")
    a = bas.createUnoService("com.sun.star.sheet.FunctionAccess")
    result = session.HasUnoMethod(a, "callFunction")
    bas.MsgBox(result) # True
  

HasUnoProperty

True itzultzen du UNO objektu batek propietatea badauka. False itzultzen du propietatea aurkitzen ez bada edo argumentu bat baliogabea bada.

Sintaxia:

session.HasUnoProperty(unoobject: uno, propertyname: str): bool

Parametroak:

unoobject: The object to inspect.

propertyname: the property as a case-sensitive string

Adibidea:

Basic lengoaian

    Dim svc As Variant
    svc = CreateUnoService("com.sun.star.sheet.FunctionAccess")
    MsgBox session.HasUnoProperty(svc, "Wildcards")
  
Python lengoaian

    bas = CreateScriptService("Basic")
    a = bas.createUnoService("com.sun.star.sheet.FunctionAccess")
    result = session.HasUnoProperty(a, "Wildcards")
    bas.MsgBox(result) # True
  

OpenURLInBrowser

Ireki Uniform Resource Locator (URL) bat nabigatzaile lehenetsian.

Sintaxia:

session.OpenURLInBrowser(url: str)

Parametroak:

url: The URL to open.

Adibidea:


    ' Basic
    session.OpenURLInBrowser("help.libreoffice.org/")
  

    # Python
    session.OpenURLInBrowser("help.libreoffice.org/")
  

RunApplication

Executes an arbitrary system command and returns True if it was launched successfully.

Sintaxia:

session.RunApplication(command: str, parameters: str): bool

Parametroak:

command: The command to execute. This may be an executable file or a document which is registered with an application so that the system knows what application to launch for that document. The command must be expressed in the current SF_FileSystem.FileNaming notation.

parameters: A list of space separated parameters as a single string. The method does not validate the given parameters, but only passes them to the specified command.

Adibidea:

Basic lengoaian

    session.RunApplication("Notepad.exe")
    session.RunApplication("C:\myFolder\myDocument.odt")
    session.RunApplication("kate", "/home/user/install.txt") ' GNU/Linux
  
Python lengoaian

    session.RunApplication("Notepad.exe")
    session.RunApplication(r"C:\myFolder\myDocument.odt")
    session.RunApplication("kate", "/home/user/install.txt") # GNU/Linux
  

SendMail

Bidali mezua -aukeran eranskinak gehituta- erabiltzailearen posta elektronikoko bezeroko hartzaileei. Erabiltzaileak mezua editatu dezake hura bidali baino lehen edo, bestela, berehala bidali dezake.

Sintaxia:

session.SendMail(recipient: str, cc: str = '', bcc: str = '', subject: str = '', body: str = '', filenames: str = '', editmessage: bool = True)

Parametroak:

recipient: An email address (the "To" recipient).

cc: A comma-separated list of email addresses (the "carbon copy" recipients).

bcc: A comma-separated list of email addresses (the "blind carbon copy" recipients).

subject: the header of the message.

body: The contents of the message as an unformatted text.

filenames: a comma-separated list of file names. Each file name must respect the SF_FileSystem.FileNaming notation.

editmessage: When True (default), the message is edited before being sent.

Adibidea:

Basic lengoaian

    session.SendMail("someone@example.com" _
        , Cc := "b@other.fr, c@other.be" _
        , FileNames := "C:\myFile1.txt, C:\myFile2.txt")
  
Python lengoaian

    session.SendMail("someone@example.com",
                     cc="john@other.fr, mary@other.be"
                     filenames=r"C:\myFile1.txt, C:\myFile2.txt")
  

SetPDFExportOptions

Modifies the PDF export settings defined in the PDF Options dialog, which can be accessed by choosing File - Export as - Export as PDF.

Calling this method changes the actual values set in the PDF Options dialog, which are used by the ExportAsPDF method from the Document service.

This method returns True when successful.

tip

Read the PDF Export wiki page to learn more about all available options.


Sintaxia:

session.SetPDFExportOptions(pdfoptions: obj): bool

Parametroak:

pdfoptions: Dictionary object that defines the PDF export settings to be changed. Each key-value pair represents an export option and the value that will be set in the dialog.

Adibidea:

Basic lengoaian

The following example changes the maximum image resolution to 150 dpi and exports the current document as a PDF file.


    Dim newSettings As Object, oDoc As Object
    Set oDoc = CreateScriptService("Document")
    Set newSettings = CreateScriptService("Dictionary")
    newSettings.Add("ReduceImageResolution", True)
    newSettings.Add("MaxImageResolution", 150)
    session.SetPDFExportOptions(newSettings)
    oDoc.ExportAsPDF("C:\Documents\myFile.pdf", Overwrite := True)
  
note

Metodo hau Basic scriptetan soilik dago erabilgarri.


UnoMethods

UNO objektu batetik deitu daitezkeen metodoen zerrenda itzultzen du. Zerrenda zeron oinarritutako matrize bat da, katez osatutakoa, eta hutsik egon daiteke.

Sintaxia:

session.UnoMethods(unoobject: uno): str[0..*]

Parametroak:

unoobject: The object to inspect.

Adibidea:

Basic lengoaian

    Dim svc : svc = CreateUnoService("com.sun.star.sheet.FunctionAccess")
    Dim methods : methods = session.UnoMethods(svc)
    Dim msg as String
    For Each m in methods
        msg = msg & m & Chr(13)
    Next m
    MsgBox msg
  
Python lengoaian

    bas = CreateScriptService("Basic")
    a = bas.createUnoService("com.sun.star.sheet.FunctionAccess")
    methods = session.UnoMethods(a)
    msg = "\n".join(methods)
    bas.MsgBox(msg)
  

UnoProperties

UNO objektu baten propietateen zerrenda itzultzen du. Zerrenda zeron oinarritutako matrize bat da, katez osatutakoa, eta hutsik egon daiteke.

Sintaxia:

session.UnoProperties(unoobject: uno): str[0..*]

Parametroak:

unoobject: The object to inspect.

Adibidea:

Basic lengoaian

    Dim svc As Variant
    svc = CreateUnoService("com.sun.star.sheet.FunctionAccess")
    MsgBox SF_Array.Contains(session.UnoProperties(svc), "Wildcards") ' True
  
Python lengoaian

    bas = CreateScriptService("Basic")
    svc = bas.createUnoService("com.sun.star.sheet.FunctionAccess")
    properties = session.UnoProperties(a)
    b = "Wildcards" in properties
    bas.MsgBox(str(b)) # True
  

UnoObjectType

Identifikatu UNO objektu baten mota kate gisa.

Sintaxia:

session.UnoObjectType(unoobject: uno): str

Parametroak:

unoobject: The object to identify.

Adibidea:

Basic lengoaian

    Dim svc As Variant, txt As String
    svc = CreateUnoService("com.sun.star.system.SystemShellExecute")
    txt = session.UnoObjectType(svc) ' "com.sun.star.comp.system.SystemShellExecute"
    svc = CreateUnoStruct("com.sun.star.beans.Property")
    txt = session.UnoObjectType(svc) ' "com.sun.star.beans.Property"
  
Python lengoaian

    bas = CreateScriptService("Basic")
    svc = bas.createUnoService("com.sun.star.system.SystemShellExecute")
    txt = session.UnoObjectType(svc) # "com.sun.star.comp.system.SystemShellExecute"
    svc = bas.createUnoService("com.sun.star.beans.Property")
    txt = session.UnoObjectType(svc) # "com.sun.star.beans.Property"
  

WebService

Eskuratu web-edukia URI batetik.

Sintaxia:

session.WebService(uri: str): str

Parametroak:

uri: URI address of the web service.

Adibidea:

Basic lengoaian

    session.WebService("wiki.documentfoundation.org/api.php?" _
        & "hidebots=1&days=7&limit=50&action=feedrecentchanges&feedformat=rss")
  
Python lengoaian

    session.WebService(("wiki.documentfoundation.org/api.php?" 
                       "hidebots=1&days=7&limit=50&action=feedrecentchanges&feedformat=rss"))
  
warning

Azpimarraren karaktere bat, "_", aurrizki gisa duten ScriptForge Basic errutina edo identifikatzaile guztiak barneko erabilerarako erreserbatuta daude. Ez dira Basic makroetan edo Python scriptetan erabili behar.