1.15.1 Getting and Setting Values for LabTalk Variables

Origin C has the ability to get and set LabTalk numeric and string values and run LabTalk scripts.

Getting and Setting LabTalk Numeric Values

The Origin C LT_get_var and LT_set_var global functions are used for getting and setting LabTalk numeric values. Numeric values include variables, system variables and object properties. Class member functions OriginObject::GetProp and OriginObject::SetProp can get and set object properties.

double dOriginVer;
LT_get_var("@V", &dOriginVer);
printf("Running Origin version %f\n", dOriginVer);

This is how to set the minimum font size used in the Data Display window.

LT_set_var("System.DataDisplay.MinFontSize", 12);

There are times when you will want to temporarily set a LabTalk variable, do some work, and then restore the LabTalk variable to its original value. There are mainly two ways to do this. The first way is the long way to do it using LT_get_var and LT_set_var.

double dProgressBar;
LT_get_var("@NPO", &dProgressBar); // get starting value
LT_set_var("@NPO", 0); // set new value
//
// do some work
//
LT_set_var("@NPO", dProgressBar); // restore starting value

The next way is the simple way using the LTVarTempChange class. To use the class you simply pass the variable name and the temporary value. The constructor saves the starting value into a data member and sets the variable to the temporary value. The destructor will restore the variable to its starting value.

{
    LTVarTempChange progressBar("@NPO", 0);
    //
    // do some work
    //
}

This is how to set and get line object color.

//This example assumes the active graph has a line object
void SetProp_Ex1(int nColor = 0, string strName = "line")
{
    GraphLayer    gl = Project.ActiveLayer();
    GraphObject    grobj;
    grobj = gl.GraphObjects(strName);
    double vv;
    if(grobj)
    {
        int nn = grobj.SetProp("color", nColor);
        out_int("SetProp return: ", nn);
        out_int("new color: ", grobj.GetProp("color"));
    }
    else
        out_str("no such obj");
}

Getting and Setting LabTalk String Values

The Origin C LT_get_str and LT_set_str global functions are used for getting and setting LabTalk string values. String values include variables, string substitution variables and object properties. Class member functions OriginObject::GetProp and OriginObject::SetProp can get and set object properties.

char szCustomDateFmt[200];
LT_get_str("System.Date.CustomFormat1$", szCustomDateFmt, 200);
printf("Custom Date Format 1:  %s\n", szCustomDateFmt);

This is how to set the font used in the Data Display window.

LT_set_str("System.DataDisplay.Font$", "Courier");

This is how to rename the active sheet of the active book.

LT_set_str("wks.name$", "MySheet");