1.15.2 Running LabTalk Script

The Origin C LT_execute global function allows you to run LabTalk script stored in a string. The Format string method can be useful in passing Origin C variables into the LabTalk script:

string strScript;
string strBook = "Book1";
int iColStart = 2, iColEnd = 5;
strScript.Format("win -a %s;plotxy %u:%u;", strBook, iColStart, iColEnd);
LT_execute(strScript);

The next example calls the LT_execute method of the Layer class instead of the global LT_execute function. When calling the global LT_execute function, the script runs and will operate on the active layer when no layer is specified by the script code. When calling the LT_execute method of the Layer class, the script runs and will operate on the layer instance instead of the active layer.

WorksheetPage wksPg("Book1");
Worksheet wks = wksPg.Layers(0);

WorksheetPage wksPgActive;
wksPgActive.Create("Origin"); // This page is now active

LT_execute("wks.colWidth=16");    // Set column widths of active layer
wks.LT_execute("wks.colWidth=8"); // Set column widths of Book1

You can also use OriginObject::SetProp function to change the LabTalk object properties. You can find more in the See_Also section.

wks.SetProp("colWidth", 8);