Servei ScriptForge.Platform

Contingut

# ScriptForge.Platform service

The Platform service provides a collection of properties about the current execution environment and context, such as:

- The hardware platform (architecture, CPU count, machine type, etc)

- Operating system information (OS type, release, version, etc)

- The LibreOffice version

- The current user name

All properties of the Platform service are read-only.

## Invocació del servei

Abans d'utilitzar el servei Platform, cal carregar o importar la biblioteca ScriptForge:

• Per a carregar macros BASIC cal fer servir la biblioteca ScriptForge mitjançant aquesta expressió:
GlobalScope.BasicLibraries.loadLibrary("ScriptForge")
• Els scripts Python requereixen una importació del mòdul scriptforge:
from scriptforge import CreateScriptService

The examples below in Basic and Python instantiate the Platform service and access the Architecture property.

##### En Basic

          GlobalScope.BasicLibraries.LoadLibrary("ScriptForge")
          Dim platform As Variant
          platform = CreateScriptService("Platform")
          MsgBox platform.Architecture

##### En Python

          from scriptforge import CreateScriptService
          svc = CreateScriptService("Platform")
          bas = CreateScriptService("Basic")
          bas.MsgBox(svc.Architecture)

## Propietats

Nom | Només de lectura | Tipus | Descripció
--- | --- | --- | ---
Architecture | Sí | String | The hardware bit architecture. Example: '32bit' or '64bit'
ComputerName | Sí | String | El nom que l'ordinador utilitza a les xarxes.
CPUCount | Sí | Integer | The number of central processing units.
CurrentUser | Sí | String | The name of the currently logged user.
Extensions | Sí | Matriu de cadenes | Returns a zero-based array of strings containing the internal IDs of all installed extensions.
FilterNames | Sí | Matriu de cadenes | Returns a zero-based unsorted array of strings containing the available document import and export filter names.
Fonts | Sí | Matriu de cadenes | Returns a zero-based array of strings containing the names of all available fonts.
FormatLocale | Sí | String | Returns the locale used for numbers and dates as a string in the format "la-CO" (language-COUNTRY).
Locale | Sí | String | Returns the locale of the operating system as a string in the format "la-CO" (language-COUNTRY). This is equivalent to the SystemLocale property.
Machine | Sí | String | The machine type. Examples are: 'i386' or 'x86_64'.
OfficeLocale | Sí | String | Returns the locale of the user interface as a string in the format "la-CO" (language-COUNTRY).
OfficeVersion | Sí | String | The actual LibreOffice version expressed as ' LibreOffice w.x.y.z (The Document Foundation)'. Exemple: «LibreOffice 7.4.1.2 (The Document Foundation, Debian and Ubuntu)»
OSName | Sí | String | The operating system type. Example: 'Darwin, Linux' or 'Windows'.
OSPlatform | Sí | String | A single string identifying the underlying platform with as much useful and human-readable information as possible. Example: 'Linux-5.8.0-44-generic-x86_64-with-glibc2.32'
OSRelease | Sí | String | The operating system's release. Example: '5.8.0-44-generic'
OSVersion | Sí | String | The operating system's build or version. Example: '#50-Ubuntu SMP Tue Feb 9 06:29:41 UTC 2021'
Printers | Sí | String array | The list of available printers as a zero-based array. The default printer is put in the first position of the list (index = 0).
Processor | Sí | String | El nom real del processador. Exemple: «amdk6». This property may return the same value as the Machine property.
PythonVersion | Sí | String | Returns the version of the Python interpreter being used as a string in the format "Python major.minor.patchlevel" (ex: "Python 3.9.7").
SystemLocale | Sí | String | Returns the locale of the operating system as a string in the format "la-CO" (language-COUNTRY). This is equivalent to the Locale property.
UserData | Sí | Dictionary | Returns a Dictionary instance containing key-value pairs in relation with Tools - Options - User Data dialog.

### Exemple:

##### En Basic

The following examples in Basic and Python illustrate how to use the Fonts property to write the names of all available fonts to the current Calc sheet starting at cell "A1":

        Dim oDoc as Object
        Dim allFonts as Object
        Dim svcPlatform as Object
        Set oDoc = CreateScriptService("Calc")
        Set svcPlatform = CreateScriptService("Platform")
        allFonts = svcPlatform.Fonts
        oDoc.setArray("~.A1", allFonts)

The example below demonstrates how to create a Calc table with all the values stored in the UserData property, which is a Dictionary service instance:

        Dim svcPlatform as Object, oUserData as Object, oDoc as Object
        Dim arrUserData As Object, currCell As String
        Set svcPlatform = CreateScriptService("Platform")
        oUserData = svcPlatform.UserData
        arrUserData = oUserData.ConvertToArray()
        Set oDoc = CreateScriptService("Calc", ThisComponent)
        oDoc.SetArray("~.A1", Array(Array("Key", "Value")))
        oDoc.SetArray("~.A2", arrUserData)

##### En Python

The examples above can be written in Python as follows:

        from scriptforge import CreateScriptService
        bas = CreateScriptService("Basic")
        doc = CreateScriptService("Calc", bas.ThisComponent)
        svc_platform = CreateScriptService("Platform")
        all_fonts = svc_platform.Fonts
        doc.setArray("~.A1", all_fonts)

        from scriptforge import CreateScriptService
        bas = CreateScriptService("Basic")
        doc = CreateScriptService("Calc", bas.ThisComponent)
        svc_platform = CreateScriptService("Platform")
        user_data = svc_platform.UserData
        arr_user_data = [[key, user_data[key]] for key in user_data]
        doc.SetArray("~.A1", (("Key", "Value"),))
        doc.SetArray("~.A2", arr_user_data)

Totes les rutines o identificadors bàsics de ScriptForge que tenen el prefix de guió baix "_" estan reservats per a ús intern. No estan pensats per utilitzar-los en macros de Basic o scripts de Python.

Temes relacionats

Identificació del sistema operatiu

Platform information with INFO("system") Calc formula

GetGuiType Funció

La biblioteca Tools