2.5.1.10 From an External Application

External applications can communicate with Origin as a COM Server. Origin's COM Object exposes various classes with properties and methods to other applications. For complete control, Origin has the Execute method which allows any LabTalk - including LabTalk callable X-Functions and OriginC function - to be executed. In this example (using Visual Basic Syntax), we start Origin, import some data, do a Gauss fit and report the peak center :

    ' Start Origin
    Dim oa
    Set oa = GetObject("", "Origin.Application")
    'oa.Execute ("doc -m 1") ' Uncomment if you want to see Origin
    Dim strCmd, strVar As String
    Dim dVar As Double

    ' Wait for Origin to finish startup compile
    ' (30 seconds is specified here, 
    '  but function may return in less than 1 second)
    oa.Execute ("sec -poc 30")
    
    'Project is empty so create a workbook and import some data
    oa.Execute ("newbook")
    strVar = oa.LTStr("SYSTEM.PATH.PROGRAM$") + _
             "Samples\Curve Fitting\Gaussian.DAT"
    oa.Execute ("string fname") ' Declare string in Origin
    oa.LTStr("fname$") = strVar ' Set its value
    oa.Execute ("impasc")       ' Import

    ' Do a nonlinear fit (Gauss)
    strCmd = "nlbegin 2 Gauss;nlfit;nlend;"
    oa.Execute (strCmd)
    ' Get peak center
    dVar = oa.LTVar("nlt.xc")
    strVar = "Peak Center at " + CStr(dVar)
    bRet = MsgBox(strVar, vbOKOnly, "Gauss Fit")

    oa.Exit
    Set oa = Nothing
    End

There are more detailed examples of COM Client Applications in the Samples\COM Server and Client folder.