[oodisc] [Fwd: Re: [api-dev] Accessing API from scripting languages]
Alex Savitsky
asav2000 на mail.ru
Пн Фев 3 11:20:05 MSK 2003
Файл большой, но вот описания запуска макроса ООо с помощью сриптового
языка (Perl, sh, др.). Макрос все равно на StarBasic, но в любом случае
это уже что-то.
-------- Исходное сообщение --------
Тема: Re: [api-dev] Accessing API from scripting languages
Дата: Sun, 02 Feb 2003 22:00:39 +0100
От: G. Jasper <g.jasper на wanadoo.nl>
Отвечать: dev на api.openoffice.org
Кому: dev на api.openoffice.org
Ссылки: <3E2883D7.4080005 на wanadoo.nl> <20030129140239.6fa60b38.mi на sun.com>
Michael Hoennig wrote (01-29-2003):
> Hi Gerrit,
>
>>I have been following your discussion with interest because I have the
>>same problem. Hal stated it somewhere like this:
>>"Now the next step is for me to understand just exactly what I send to
>>port 8100 from a scripting language to get it to run a OOo basic
>>program. I figure I'll put all the OOo commands in OOo basic, then I
>>just call each one I need from Perl or a Bash script."
>>
>>This concept led Michael to the question/remark:
>>"Do I understand correctly that you want to use the port directly from
>>an external scripting language instead of using UNO on your side of the
>>connection? I have to say that I don't like this idea."
>>
>>Why not? I like the idea, and I have tried to get it running as follows:
>>
>
> Of couse, it could work, UNO does that - just in C. But it will be a hell
> of a lot of work! It is like reimplementing UNO. And this mailig list is
> definitely the WRONG list for this issue. If any, then the UDK list is
> right.
>
> Michael
Marten Feldtmann schrieb (01-18-2003):
>> G. Jasper schrieb:
>>
>> My idea, and I think that is the same as Hal's, is to use this transmission
>> to start action in OOo by triggering a Basic routine (sub).
>> The script does not have to put anything into OOo; the Basic sub can get
>> info from any script file (Bash, ksh , whatever) like this:
>>
>>
> Yes, that would be a nice and easy way to call Basic routines, but
> actually that would be too easy :-))
>
> Marten
I have been snooping around, e.g. in the dev на openoffice.org list and
I am sorry to say, no, I am happy to say that it is as simple as this:
>From: John Rice <john.rice на sun.com>
>Date: Thu, 16 Jan 2003 14:47:53 +0000
>Subject: Re: [dev] Accessing OOo through Perl
>Hal,
>As Joerg pointed out the format is:
>soffice "macro:///<library-name>/<macro-name>()"
>For example to launch the AutoText macro in the Gimmics library:
>soffice "macro:///Gimmicks.AutoText.Main()"
I lost Joerg's e-mail, but I think he pointed out that in an already
running OOo file this will not open another instance of it, but just run
the intended macro.
That's it !!!
I have been experimenting with this, resulting in a kind of demo as follows:
First a Basic macro in the spreadsheet just to start some action
outside OOo (may also be used to activate an interval timer like an
alarm clock,that could just call you back).
'Sub scalcToShell
'
Dim iNumber As Integer
'
Dim aFile As String
'
sLine = "10" REM sets 10 seconds sleep for the next script
'
aFile = "file:///usr/gerrit/nt_download/shellSetAlarm"
'
iNumber = Freefile
'
Open aFile For Output As #iNumber
'
Print #iNumber, sLine
'
Close #iNumber
'
'
shell( "/usr/gerrit/nt_web/shell_sleep_call" )
'End Sub
The "shell" call starts the next script:
#!/bin/bash
# shell_sleep_call
# G.Jasper
# Written 30-01-2003
#Test script, that will be called by the spreadsheet program #(Basic)
#First it obtains the time to sleep from file shellSetAlarm
#After sleeping that interval it sets action in file
#shellActionCode, then
calls the script file that will start #action in the spreadsheet file
"newtables".
read fld1 fld2 < /usr/gerrit/nt_download/shellSetAlarm
sleep $fld1
printf "%b\n" 'actionA' > \ /usr/gerrit/nt_download/shellActionCode
#printf "%b\n" 'actionB' > \ #
/usr/gerrit/nt_download/shellActionCode
/usr/gerrit/nt_web/shell_run_macro
The last command starts the next script:
#!/bin/bash
# shell_run_macro
# G.Jasper
# Written 22-01-2003, last edited 02-02-2003
#This script will activate (trigger) the specified Basic macro #in the
opened spreadsheet file (newtables.sxc).
#Different commands have been tested, with results as mentioned.
#Uncomment the desired command (only one at a time!)
#The next command only works when the spreadsheet file is #active,
i.e. has
the focus in the current desktop.
#/usr/gerrit/OOo643C/program/scalc \ #
"macro://./Standard.Test_new.shellToScalcDemo"
#The next command works, whether the spreadsheet file has focus #or
not. I
prefer this one.
/usr/gerrit/OOo643C/program/scalc \
"macro://newtables/Standard.Test_new.shellToScalcDemo"
#The next command works when soffice is open, also when the
#spreadsheet is not
the active file. There is a snag here.
#/usr/gerrit/OOo643C/program/soffice \ #
"macro:///Standard.shellCalls.shellToSoffice"
sleep 2
FETCHTIME=$( date +%H:%M:%S )
printf "%b\n" $FETCHTIME > /usr/gerrit/nt_download/id_timer #an
extra check
The script above triggers this OOo Basic macro in the file "newtables"
(if not shellToSoffice in soffice):
'Sub shellToScalcDemo
'
oDocument = ThisComponent
'
oSheet = oDocument.Sheets.getByName( "import" )
'
oCell = oSheet.GetCellRangeByName( "$O$2" )
'
oCell.String = "shellToScalcDemo"
'
oCell = oSheet.GetCellRangeByName( "$O$3" )
'
oCell.Value = Now
'
'
MsgBox "This was called by a shell script file, calling '
shellToScalcDemo "
'
oDocument.CurrentController.Select(oCell)
'
Call callFromShell
'End Sub
which calls:
'Sub callFromShell
'
Dim iNumber As Integer
'
Dim aFile As String
'REM Get code for required action.
'
aFile = "file:///usr/gerrit/nt_download/shellActionCode"
'
iNumber = Freefile
'
Open aFile For Input As #iNumber
'
Line Input #iNumber, sLine
'
Close #iNumber
'
'
if sLine = "actionA" then
'
MsgBox sLine & " wanted by shell"
'
Call reactionA
'
elseif sLine = "actionB" then
'
MsgBox sLine & " wanted by shell"
'
Call reactionB
'
end if
'End Sub
which branches as desired:
'
'Sub reactionA
'
oSheet = oDocument.Sheets.getByName( "d_table" )
'
oCell = oSheet.GetCellRangeByName( "$B$1" )
'
oCell.String = "reacted as A"
'End Sub
'
'Sub reactionB
'
oSheet = oDocument.Sheets.getByName( "d_table" )
'
oCell = oSheet.GetCellRangeByName( "$B$1" )
'
oCell.String = "reacted as B"
'End Sub
This runs like clockwork !
The snag mentioned in shell_run_macro with regard to the command
/usr/gerrit/OOo643C/program/soffice \
macro:///Standard.shellCalls.shellToSoffice
relates to the fact that this triggers a macro in module
soffice/Standard.shellCalls
---------------------------------------------------------------------
To unsubscribe, e-mail: dev-unsubscribe на api.openoffice.org
For additional commands, e-mail: dev-help на api.openoffice.org
--
--
Best regards,
Savitsky Alex
Подробная информация о списке рассылки Oo-discuss