The example scripts below demonstrate COM automation via .vbs scripts and via web page implementing VBscript.
To run scripts in Echoview you will need to have a Scripting module license.
If you have any trouble with the examples below please contact Echoview for support.
|
COM script example |
Description |
|
COM script for a single export. |
|
|
COM script for multiple exports from multiple variables. |
|
|
Multiple exports from multiple variables in multiple EV files |
COM script for multiple exports from multiple variables in multiple EV files. |
|
Multiple exports from multiple variables in all EV files in a folder |
COM script for multiple exports from multiple variables in all EV files in a folder. |
|
Lists the variables in any open EV files. |
|
|
Picks a line on a particular variable in a particular file and exports an .evl file for the picked line. |
|
| Web page COM | Uses an Internet Explorer web page script to list all the variables in a selected EV file. |
|
Windows Script File (.wsf) with one job and two scripts (VBScript and JScript). |
The examples can be edited to create your own scripts. The text in maroon are the strings that will need to be changed to suit your own files and export needs.
To try the sample VBS script:
This script will open FileA.EV located in C:\Program files\Myriax\Echoview\Echoview4\Example scripts\EVFiles folder. The variable Sv Q1 telegrams T1 will be processed and an Integration by Regions will be exported to the output folder Script1Output. The output file will be called: FileA.EV-Sv1-ARIN.csv.
Note that the output folder must exist prior to running the script or the export will fail.
'''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''' ' A single export '''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''' ' Open the EV file Dim EvApp: Set EvApp = CreateObject("EchoviewCom.EvApplication") Dim EvFile: Set EvFile = EvApp.OpenFile("C:\Program files\Myriax\Echoview\Echoview4\Example scripts\EVFiles\FileA.EV") If EvFile Is Nothing Then MsgBox "Failed to open EV file" Else ''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''' ' Get the variable Dim Var: Set Var = EvFile.Variables.FindByName("Sv Q1 telegrams T1") If Var Is Nothing Then MsgBox "Failed to find variable" Else Dim VarAc: Set VarAc = Var.AsVariableAcoustic If VarAc Is Nothing Then MsgBox "Variable is not acoustic" Else ''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''' ' Export the variable If Not VarAc.ExportIntegrationByRegions("C:\Program files\Myriax\Echoview\Echoview4\Example scripts\Script1Output\FileA-Sv1-ARIN.csv", Nothing) Then MsgBox "Failed to export by regions" End If End If End If End If ''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''' ' Tidy up EvApp.CloseFile(EvFile) EvApp.Quit
To try the sample VBS script:
This script will open FileA.EV located in C:\Program files\Myriax\Echoview\Echoview4\Example scripts folder. The script will do an Integration by Regions and an Integration by Cells on two variables: Sv Q1 telegrams T1 and Sv Q2 telegrams T2.
Note that the output folder must exist prior to running the script or the export will fail.
''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''' ' Multiple exports from multiple variables ''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''' ' The main program Dim EvApp: Set EvApp = CreateObject("EchoviewCom.EvApplication") Dim EvFile: Set EvFile = EvApp.OpenFile("C:\Program files\Myriax\Echoview\Echoview4\Example scripts\EVFiles\FileA.EV") If EvFile Is Nothing Then MsgBox "Failed to open EV file" EvApp.Quit WScript.Quit End If Export("Sv Q1 telegrams T1") Export("Sv Q2 telegrams T2") EvApp.CloseFile(EvFile) EvApp.Quit ''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''' ' A subroutine to export the named variable Sub Export(VarName) Dim Var: Set Var = EvFile.Variables.FindByName(VarName) If Var Is Nothing Then MsgBox "Failed to find variable '" & VarName & "'" Exit Sub End If Dim VarAc: Set VarAc = Var.AsVariableAcoustic If VarAc Is Nothing Then MsgBox "Variable '" & VarName & "' is not acoustic" Exit Sub End If If Not VarAc.ExportIntegrationByRegions("C:\Program files\Myriax\Echoview\Echoview4\Example scripts\Script1Output\FileA-" & Left(VarName, 2) & Right(VarName, 1) & "-ARIN.csv", Nothing) Then MsgBox "Failed to export '" & VarName & "' by regions" End If If Not VarAc.ExportIntegrationByCells("C:\Program files\Myriax\Echoview\Echoview4\Example scripts\Script1Output\FileA-" & Left(VarName, 2) & Right(VarName, 1) & "-ACIN.csv", Nothing) Then MsgBox "Failed to export '" & VarName & "' by cells" End If End Sub
To try the sample VBS script:
This script will open FileA.EV and FileB.EV located in C:\Program files\Myriax\Echoview\Echoview4\Example scripts\EVFiles folder. The script will run two exports on two variables in two EV files.
Note that the output folder must exist prior to running the script or the export will fail.
''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''' ' Multiple exports from multiple variables in multiple EV files ''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''' Dim fso: Set fso = CreateObject("Scripting.FileSystemObject") Dim EvApp: Set EvApp = CreateObject("EchoviewCom.EvApplication") ExportFromFile "C:\Program files\Myriax\Echoview\Echoview4\Example scripts\EVFiles\FileA.EV" ExportFromFile "C:\Program files\Myriax\Echoview\Echoview4\Example scripts\EVFiles\FileB.EV" EvApp.Quit ''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''' ' A subroutine to export from the named file Sub ExportFromFile(FileName) Dim EvFile: Set EvFile = EvApp.OpenFile(FileName) If EvFile Is Nothing Then MsgBox "Failed to open EV file '" & FileName & "'" Exit Sub End If ExportVariable EvFile, "Sv Q1 telegrams T1" ExportVariable EvFile, "Sv Q2 telegrams T2" EvApp.CloseFile(EvFile) End Sub ''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''' ' A subroutine to export the named variable Sub ExportVariable(EvFile, VarName) Dim Var: Set Var = EvFile.Variables.FindByName(VarName) If Var Is Nothing Then MsgBox "Failed to find variable '" & VarName & "' in EV file '" & EvFile.FileName & "'" Exit Sub End If Dim VarAc: Set VarAc = Var.AsVariableAcoustic If VarAc Is Nothing Then MsgBox "Variable '" & VarName & "' is not acoustic in EV file '" & EvFile.FileName & "'" Exit Sub End If Dim OutFileName: OutFileName = CreateFileName(EvFile.FileName, VarName, "ARIN") If Not VarAc.ExportIntegrationByRegions(OutFileName, Nothing) Then MsgBox "Failed to export '" & VarName & "' by regions from EV file '" & EvFile.FileName & "'" End If OutFileName = CreateFileName(EvFile.FileName, VarName, "ACIN") If Not VarAc.ExportIntegrationByCells(OutFileName, Nothing) Then MsgBox "Failed to export '" & VarName & "' by cells from EV file '" & EvFile.FileName & "'" End If End Sub ''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''' ' A function to create the output file name Function CreateFileName(FileName, VarName, OpName) Dim FolderName: FolderName = "C:\Program files\Myriax\Echoview\Echoview4\Example scripts\Script1Output\" Dim File: Set File = fso.GetFile(FileName) CreateFileName = FolderName & Left(File.Name, Len(File.Name) - 3) & "-" & Left(VarName, 2) & Right(VarName, 1) & "-" & OpName & ".csv" End Function
To try the sample VBS script:
This script will run the same set of export tasks on the same set of variables in EVERY EV file in the input folder.
''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''' ' Multiple exports from multiple variables in all EV files in a folder ''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''' Dim FolderName: FolderName = "C:\Program files\Myriax\Echoview\Echoview4\Example Scripts\EVFiles" Dim fso: Set fso = CreateObject("Scripting.FileSystemObject") Dim Files: Set Files = fso.GetFolder(FolderName).Files Dim EvApp: Set EvApp = CreateObject("EchoviewCom.EvApplication") For Each File In Files ExportFromFile FolderName & "\" & File.Name Next EvApp.Quit ''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''' ' A subroutine to export from the named file Sub ExportFromFile(FileName) If (UCase(Right(FileName, 3)) ".EV" Or UCase(Right(FileName, 12)) = " (BACKUP).EV") Then Exit Sub End If Dim EvFile: Set EvFile = EvApp.OpenFile(FileName) If EvFile Is Nothing Then MsgBox "Failed to open EV file '" & FileName & "'" Exit Sub End If ExportVariable EvFile, "Sv Q1 telegrams T1" ExportVariable EvFile, "Sv Q2 telegrams T2" ExportVariable EvFile, "Sv Q3 telegrams T3" EvApp.CloseFile(EvFile) End Sub ''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''' ' A subroutine to export the named variable Sub ExportVariable(EvFile, VarName) Dim Var: Set Var = EvFile.Variables.FindByName(VarName) If Var Is Nothing Then MsgBox "Failed to find variable '" & VarName & "' in EV file '" & EvFile.FileName & "'" Exit Sub End If Dim VarAc: Set VarAc = Var.AsVariableAcoustic If VarAc Is Nothing Then MsgBox "Variable '" & VarName & "' is not acoustic in EV file '" & EvFile.FileName & "'" Exit Sub End If Dim OutFileName: OutFileName = CreateFileName(EvFile.FileName, VarName, "ARIN") If Not VarAc.ExportIntegrationByRegions(OutFileName, Nothing) Then MsgBox "Failed to export '" & VarName & "' by regions from EV file '" & EvFile.FileName & "'" End If OutFileName = CreateFileName(EvFile.FileName, VarName, "ACIN") If Not VarAc.ExportIntegrationByCells(OutFileName, Nothing) Then MsgBox "Failed to export '" & VarName & "' by cells from EV file '" & EvFile.FileName & "'" End If OutFileName = CreateFileName(EvFile.FileName, VarName, "ABIN") If Not VarAc.ExportIntegrationByRegionsByCells(OutFileName, Nothing) Then MsgBox "Failed to export '" & VarName & "' by regions by cells from EV file '" & EvFile.FileName & "'" End If End Sub ''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''' ' A function to create the output file name Function CreateFileName(FileName, VarName, OpName) Dim FolderName: FolderName = "C:\Program files\Myriax\Echoview\Echoview4\Example scripts\Script1Output\" Dim File: Set File = fso.GetFile(FileName) CreateFileName = FolderName & Left(File.Name, Len(File.Name) - 3) & "-" & Left(VarName, 2) & Right(VarName, 1) & "-" & OpName & ".csv" End Function
To try the sample VBS script:
This script demonstrates:
''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''' ' List variables ''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''' ' Attach to Echoview Dim EvApp: Set EvApp = CreateObject("EchoviewCom.EvApplication") If Not EvApp.IsLicensed Then MsgBox "Echoview is not licensed for COM scripting" WScript.Quit End If ''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''' ' List files Dim FileIndex for FileIndex = 0 to EvApp.EvFiles.Count-1 Dim EvFile: Set EvFile = EvApp.EvFiles.Item(FileIndex) ''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''' ' List variables EvApp.Log "EV File '" & EvFile.FileName & "' contains " & EvFile.Variables.Count & " variables" Dim VarIndex for VarIndex = 0 to EvFile.Variables.Count-1 Dim Var: Set Var = EvFile.Variables.Item(VarIndex) ''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''' ' Report variable type Dim Description: Description = " is of unspecified type" If Not Var.AsVariableAcoustic Is Nothing Then Description = " is acoustic" If Not Var.AsVariableVirtual Is Nothing Then Description = Description & " and virtual" End If Elseif Not Var.AsVariableVirtual Is Nothing Then Description = " is virtual" End If EvApp.Log Var.Name & Description Next Next
To try the sample VBS script:
Note: The output folder 'Picked Lines' must exist prior to running the script or the export will fail.
This script demonstrates:
''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''' ' Pick Line ''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''' Dim ScriptsFolder: ScriptsFolder = "C:\Program Files\Myriax\Echoview\Echoview4\Example Scripts\" Dim FSO: Set FSO = CreateObject("Scripting.FileSystemObject") Dim fOut: Set fOut = FSO.OpenTextFile("PickLine.txt", 2, true) Dim EvApp: Set EvApp = CreateObject("EchoviewCom.EvApplication") fOut.WriteLine "Echoview version: " & EvApp.Version & " at " & Date & " " & Time ' ' Open the EV file Dim EvFile: Set EvFile = EvApp.OpenFile(ScriptsFolder & "EVFiles\FileA.EV") If EvFile Is Nothing Then fOut.WriteLine "Could not open EV file - " & EvApp.GetLastLogMessage WScript.Quit End If fOut.WriteLine "EV file '" & EvFile.FileName & "'"PickLine "Sv Q1 telegrams T1" ' ' Close EV file and quit If Not EvApp.CloseFile(EvFile) Then fOut.WriteLine EvApp.GetLastLogMessage End If EvApp.Quit'''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''' ' Pick line in the variable Sub PickLine(VarName) ' ' Get the variable Dim Var: Set Var = EvFile.Variables.FindByName(VarName) If Var Is Nothing Then fOut.WriteLine EvApp.GetLastLogMessage Exit Sub End If Dim VarAc: Set VarAc = Var.AsVariableAcoustic If VarAc Is Nothing Then fOut.WriteLine Var.Name & " is not an acoustic variable" Exit Sub End If ' ' Pick Line Dim Line: Set Line = VarAc.PickLine(VarName & " - Picked Line") If Line Is Nothing Then fOut.WriteLine EvApp.GetLastLogMessage Exit Sub Else fOut.WriteLine "'" & Line.Name & "'" End If ' ' Export line Dim FileName: FileName = ScriptsFolder & "Picked Lines\" & VarName & ".evl" If Line.Export(FileName) Then fOut.WriteLine "Exported to '" & FileName & "'" Else fOut.WriteLine EvApp.GetLastLogMessage End If End Sub
This example uses an ActiveX object. This is supported by Microsoft's Internet Explorer but not by Mozilla based browsers like Firefox and Netscape. You may need to customize the security settings in Internet Explorer.
Various security settings affect the execution of ActiveX objects in web pages. The default settings on most Windows XP systems safeguard against exploitation by embedded ActiveX objects and implement a Medium-Low security level. If the sample script below does not function, select the Low security level as follows:
To try the sample web page:
Note: This html script executes once; it connects to Echoview, opens and then closes the EV file and lists the variables in the EV file. To list variables from another EV file use the Internet Explorer Back arrow and follow the script steps again.
<html>
<head>
<script language="VBScript" type="text/vbscript">
'------------------------------------------------------------------------------
Dim FSO: Set FSO = CreateObject("Scripting.FileSystemObject")
Dim EvApp: Set EvApp = Nothing
'------------------------------------------------------------------------------
Sub OpenEchoview()
If EvApp Is Nothing Then
Set EvApp = CreateObject("EchoviewCom.EvApplication")
End If
End Sub
'------------------------------------------------------------------------------
Sub DisconnectEchoview
Set EvApp = Nothing
End Sub
'------------------------------------------------------------------------------
Sub ListVariables()
If EvApp Is Nothing Then
Exit Sub
End If
Dim FileName: FileName = document.getElementById("txtEVFile").value
If FileName = "" Then
Exit Sub
End If
Dim EvFile: Set EvFile = EvApp.OpenFile(FileName)
If Not EvFile Is Nothing Then
Dim BaseName: BaseName = FSO.GetFileName(FileName)
Document.Open
Document.Writeln "<HTML><TITLE>Variables in " & BaseName & "</TITLE>"
Document.Writeln "<BODY>"
Document.Writeln "<H1>" & BaseName & "</H1>"
Document.Writeln "<UL>"
For v = 0 To EvFile.Variables.Count - 1
Dim Var: Set Var = EvFile.Variables(v)
If Not Var Is Nothing Then
Dim MeasurementCount: MeasurementCount = ""
Dim VarAc: Set VarAc = Var.AsVariableAcoustic
If Not VarAc Is Nothing Then
MeasurementCount = " (" & CStr(VarAc.MeasurementCount) & " pings)"
End If
Document.Writeln "<LI>" & Var.FullName & " " & Var.ShortName & MeasurementCount & "</LI>"
End If
Next
Document.Writeln "</UL>"
End If
Document.Writeln "</BODY>"
Document.Close
EvApp.CloseFile(EvFile)
End Sub
'------------------------------------------------------------------------------
</script>
</head>
<body>
<form action="" method="post" enctype="multipart/form-data" name="form1">
<input name="btnOpenConnect" type="button" id="btnOpenConnect" value="Open or Connect to Echoview" onClick="OpenEchoview()">
<input name="btnDisconnect" type="button" id="btnDisconnect" value="Disconnect from Echoview" onClick="DisconnectEchoview()">
<br>
<input name="txtEVFile" type="file" id="txtEVFile" size="100">
<br>
<input name="btnListVariables" type="button" id="btnListVariables" value="List Variables" onClick="ListVariables()">
</form>
</body>
</html>