REM ***** BASIC ***** ' Somes useful tools used in OOoLilyPondMusic '********************************************************* ' Add a slash if necessary Function AddSlash( sPath as String) as String If Right(sPath,1) = "/" then AddSlash = sPath else AddSlash = sPath & "/" end if end Function 'Executes the command sCommand in a bash and returnes when finished 'The command must not include any single quote (') sub BashCommand(sCommand) Shell("bash -c '" & sCommand & "'", 1, "", True) end sub '********************************************************** ' Check the existance of the file... Function CheckFile( sUrl as String, ErrorMsg as String) As Boolean ' Test the existance of the OOoLilyPond script ... if FileExists(sUrl) then CheckFile = False else if ErrorMsg = "OOoLilyPond" then _ ErrorMsg = "Cannot find " & sUrl & chr(10) & "Check your installation..." Msgbox ErrorMsg CheckFile = True end if End Function Function GetOSType() If GetPathSeparator() = "\" Then GetOSType="Windows" Else GetOSType="Unix" End If End Function sub InspectObject(vObj) vObj=ThisComponent() MsgBox vObj.getImplementationName 'MsgBox vObj.dbg_methods 'Methods for this object. 'MsgBox vObj.dbg_supportedInterfaces 'Interfaces for by this object. 'MsgBox vObj.dbg_properties 'Properties for this object. end sub '*********************************************************** ' Import graphic from URL into the clipboard. ' Inspired from OOoForums Danny's code Sub ImportGraphicIntoClipboard(cURL) ' MsgBox(cURL) oDispatcher = createUnoService( "com.sun.star.frame.DispatchHelper" ) ' Import the graphic from URL into a new draw document. Dim arg1(0) As New com.sun.star.beans.PropertyValue arg1(0).Name = "Hidden" arg1(0).Value = true oDrawDoc = StarDesktop.loadComponentFromURL( cURL, "_blank", 0, arg1() ) oDrawDocCtrl = oDrawDoc.getCurrentController() ' Get the shape... oDrawPage = oDrawDoc.DrawPages(0) oImportShape = oDrawPage(0) ' Get the dimension of the image... oShapeSize = oImportShape.Size() ' Strange bug with the eps and emf format... correction of the size if sFormat = "eps" then oShapeSize.Width = oShapeSize.Width * 0.99 if sFormat = "eps" then oShapeSize.Height = oShapeSize.Height * 0.91 if sFormat = "emf" then oShapeSize.Width = oShapeSize.Width * 1.13 if sFormat = "emf" then oShapeSize.Height = oShapeSize.Height * 1.1 ' Copy the image to clipboard and close the draw document oDrawDocCtrl.select(oImportShape) Dim Array() oDispatcher.executeDispatch( oDrawDocCtrl.Frame, ".uno:Copy", "", 0, Array() ) oDrawDoc.dispose() End Sub '************************************************************ Sub PrintFile(sFile as String) if not FileExists(sTmpPath & sFile) then Msgbox "Error : the file " & TmpPath & sFile & " doesn't exist..." exit sub end if iNumber = Freefile Open sTmpPath & sFile For Input As iNumber While not eof(iNumber) Line Input #iNumber, sLine 'if sLine <> "" then sMsg = sMsg & sLine & chr(10) wend Close #iNumber Msgbox sMsg End sub Sub SortStringArray(StringArray As Variant) Dim l, u as Integer l=LBound(StringArray()) u=UBound(StringArray()) Dim i, j As Integer Dim sTemp As String For i = l To (u - 1) For j = (i + 1) To u If StringArray(i) > StringArray(j) Then sTemp = StringArray(i) StringArray(i) = StringArray(j) StringArray(j) = sTemp End If Next j Next i End Sub ' The Function returns the name of a file that does not already exist. ' This prevents unintended overwriting of existing files. Function TmpFileName(sPrefix , sSuffix As String) As String Do TmpFileName=sPrefix & Int(Str(Rnd*1e6)) & sSuffix Loop While FileExists(TmpFileName) End Function ' Did not achieve to run lilypond directly with the Shell command and the ' Output redirected to files. ' I tried: Shell("cmd /c lilypond >file1 2>file2") ' But this did not work :-( ' Now I write down the command in a batch file and call it with Shell. Sub WindowsCommand(sCommand as String) Dim sBatFile As String Dim iNumber As Integer sBatFile=TmpFileName(ConvertFromURL(sTmpPath) & "CommandCallFromOOo_",".bat") iNumber = Freefile Open sBatFile For Output As #iNumber Print #iNumber, sCommand Close #iNumber Shell(sBatFile,1,"",True) Kill(sBatFile) End Sub