OriginPro
 
Loading...
Searching...
No Matches
originpro.utils Namespace Reference

Classes

class  _LTTMPOUTSTR
 

Functions

 lt_float (formula)
 
 lt_int (formula)
 
 get_lt_str (vname)
 
 set_lt_str (vname, value)
 
 lt_exec (labtalk)
 
 messagebox (msg, cancel=False)
 
 set_lt_var (name, value)
 
 attach ()
 
 detach ()
 
 exit ()
 
 get_show ()
 
 set_show (show=True)
 
 ocolor (rgb)
 
 to_rgb (orgb)
 
 get_file_ext (fname)
 
 get_file_parts (fname)
 
 last_backslash (fpath, action)
 
 path (type='u')
 
 wait (type='r', sec=0)
 
 file_dialog (type, title='')
 
 origin_class (name)
 
 active_obj (name)
 
 color_col (offset=1, type='m')
 
 modi_col (offset=1)
 
 org_ver ()
 
 make_DataRange (*args, rows=None)
 
 attrib_key (name)
 
 _tree_node_get_attributes_key_for_root ()
 
 _tree_dict_is_key_attributes (key)
 
 _tree_node_name_to_attributes_key_name (nodename)
 
 _dict_to_xml_element_atts (dd, parent, key)
 
 _dict_to_xml_element (dd, parent, bAttributes)
 
 _dict_to_xml (dd, bAttributes=False)
 
 lt_dict_to_tree (dd, treename, add_tree=False, check_attributes=False)
 
 _tree_node_attributes_to_dict (dd, node, bRoot=False)
 
 _tree_to_dict (dd, node, bAttributes=False)
 
 lt_tree_to_dict (name, add_attributes=False)
 
 lt_empty_tree ()
 
 lt_delete_tree (name)
 
 evaluate_FDF (ffname, indepvars, parameters)
 
 olab_download (file)
 
 _CreateSysVar ()
 

Variables

 PATHSEP = os.path.sep
 
str _TREE_NODE_GET_ATTRIBUTES_KEY_PREFIX = '___'
 
 sysvar = _CreateSysVar()
 

Detailed Description

originpro
A package for interacting with Origin software via Python.
Copyright (c) 2020 OriginLab Corporation

Function Documentation

◆ _dict_to_xml()

originpro.utils._dict_to_xml ( dd,
bAttributes = False )
protected
Converts dictionary dd to an xml tree, then converts the xml tree to an xml string
and returns it.
Parameters:
    dd (dictionary)
Returns:
    xml string obtained from xml tree obtained from dd
Example:
def prepare_dict():
    dictsub = {"KeyOne":"OneValue", "KeyTwo":-0.0987, "KeyThree":345678}
    dictret = {"FirstKey":"FirstValue", "SecondKey":99.88, "ThirdKey":dictsub, "FourthKey":-543}
    return dictret

thedict = prepare_dict()
xml = op._dict_to_xml(thedict)
print(xml)

◆ active_obj()

originpro.utils.active_obj ( name)
Get active object
Parameters:
    name(string):object type name
Returns:
    active object
Examples:
    page=op.active_obj('Page')

◆ attach()

originpro.utils.attach ( )
Attach to exising Origin instance
Parameters:
    none
Return:
    none
Example:
    op.attach()

◆ color_col()

originpro.utils.color_col ( offset = 1,
type = 'm' )
Generate Origin's internal OColor to use in data plot's color setting
Parameters:
    offset (int): worksheet column offset to the plot's Y column
    type (str): 'm' for Colormap, 'n' = Indexing, 'r' = RGB
Returns:
    OColor
Examples:
    plot.color = op.color_col()# use next column to Y as color map values
    plot.color = op.color_col(1,'n') #use index color, column needs to contain 1,2,3 etc
    plot.colormap="fire"

◆ detach()

originpro.utils.detach ( )
Detach Origin instance
Parameters:
    none
Return:
    none
Example:
    op.detach()

◆ evaluate_FDF()

originpro.utils.evaluate_FDF ( ffname,
indepvars,
parameters )
Evaluate FDF function
Parameters:
    ffname (str): Name of the Fitting Function
    indepvars(list): Independent Variables values, can be list of list if multiple independents
    parameters(list): Parameter values
Returns:
    A list of Dependent Variable values
Examples:
    vx = [1, 2, 3]
    vy = op.evaluate_FDF('Gauss', vx, [1, 2, 3, 4])

◆ exit()

originpro.utils.exit ( )
exit the application
Parameters:
    none
Return:
    none
Example:
    op.exit()

◆ file_dialog()

originpro.utils.file_dialog ( type,
title = '' )
open a file dialog to pick a single file
Parameters:
    type (str): 'i' for image, 't' for text, 'o' for origin, or a file extension like '*.png'

Returns:
    if user cancel, an empty str, otherwise the selected file path
Examples:
    fn=op.file_dialog('o')
    fn=op.file_dialog('*.png;*.jpg;*.bmp')

◆ get_file_ext()

originpro.utils.get_file_ext ( fname)
Given a full path file name, return the file extension.

Parameters:
    fname (str): Full path file name

Returns:
    (str) File extension

Examples:
    ext = op.get_file_ext('C:\path\to\somefile.dat')

◆ get_file_parts()

originpro.utils.get_file_parts ( fname)
Given a full path file name, return the path, file name, and extension as a Python list object.

Parameters:
    fname (str): Full path file name

Returns:
    (list) Contains path, file name, and extension

Examples:
    parts = op.get_file_parts('C:\path\to\somefile.dat')

◆ get_lt_str()

originpro.utils.get_lt_str ( vname)
Parameters:
    vname (str): a LabTalk string
Returns:
    return a LabTalk string variable value. To get LabTalk numeric values,
    use lt_int or lt_float
Examples:
    #AppData path for the installed Origin
    >>> op.get_lt_str('%@Y')
See Also:
    lt_int, lt_float

◆ get_show()

originpro.utils.get_show ( )
If the Application is visible or not
Parameters:
    none
Return:
    True if visible, otherwise False
Example:
    op.get_show()

◆ last_backslash()

originpro.utils.last_backslash ( fpath,
action )
Add or trim a backslash to/from a path string.

Parameters:
    fpath (str): Path
    action (str): Either 'a' for add backslash or 't' for trim backslash

Returns:
    (str) Path either with added backslash or without trimmed backslash

Examples:
    >>>op.last_backslash(op.path(), 't')

◆ lt_delete_tree()

originpro.utils.lt_delete_tree ( name)
Delete a Labtalk tree
Parameters:
    name(string):name of the Labtalk tree
Returns:
    none
Examples:
    op.lt_delete_tree('tr')

◆ lt_dict_to_tree()

originpro.utils.lt_dict_to_tree ( dd,
treename,
add_tree = False,
check_attributes = False )
Converts dictionary dd to an xml tree string and sets the value of a LabTalk tree variable
to the xml tree string. If bAddTreeVar is False and the tree variable does not already exist,
the tree variable will not be added. Pass True as bAddTreeVar if you want to make sure that
the tree variable is added first if it does not exist.
Parameters:
    dd (dictionary)
    treename(str): the name of the tree variable
    add_tree:If True, the tree variable will be added if it does not exist
    check_attributes(bool):whether to check attributes
Returns:
    none
Examples:
    dd={'name':'bob', 'age':14, 'class':'p1'}
    op.lt_dict_to_tree(dd,'tr',True)

◆ lt_empty_tree()

originpro.utils.lt_empty_tree ( )
Parameters:
    none
Returns:
    An empty Labtalk tree
Examples:
    tr=op.lt_empty_tree()

◆ lt_exec()

originpro.utils.lt_exec ( labtalk)
run LabTalk script
Parameters:
    labtalk(string):LabTalk script
Returns:
    bool value that indicate Whether the script is run successfully
Examples:
    op.lt_exec('impasc -dm')

◆ lt_float()

originpro.utils.lt_float ( formula)
Parameters:
    formula (str): any LaTalk expression
Returns:
    the result of a LabTalk expression
Examples:
    #Origin Julian days value
    >>>op.lt_float('date(1/2/2020)')
    #get Origin version number
    >>>op.lt_float('@V')

See Also:
    get_lt_str, lt_int

◆ lt_int()

originpro.utils.lt_int ( formula)
Parameters:
    formula (str): any LaTalk expression
Returns:
    the result of a LabTalk expression as int, see lt_float()
Examples:
    >>> op.lt_int('color("green")')

See Also:
    get_lt_str, lt_float

◆ lt_tree_to_dict()

originpro.utils.lt_tree_to_dict ( name,
add_attributes = False )
Get Labtalk tree as dict
Parameters:
    name (str): Name of the Labtalk tree
    add_attributes(bool): add the attributes from the tree as nodes
Returns:
    dict to hold Labtalk tree content
Examples:
    wks = op.new_sheet()
    data = [1,2,3,4,5]
    wks.from_list(0, data)
    wks.from_list(1, data)
    op.lt_exec('fitlr (1,2)')
    dd = op.lt_tree_to_dict('fitlr')

◆ make_DataRange()

originpro.utils.make_DataRange ( * args,
rows = None )
Make Origin DataRange object

◆ messagebox()

originpro.utils.messagebox ( msg,
cancel = False )
open a message box
Parameters:
    msg(str): the text to prompt
    cancel(bool): True if OK Cancel, False if just OK

Return:
    False if has cancel button and user click Cancel

Examples:
    nn = op.messagebox('this is a test', True)
    if not nn:
        op.messagebox('you clicked cancel')
    else:
        op.messagebox('you click ok')

◆ modi_col()

originpro.utils.modi_col ( offset = 1)
Generate Origin's internal modifier (uint) value to use in data plot's various setting
Parameters:
    offset (int): worksheet column offset to the plot's Y column
Returns:
    uint
Examples:
    plot.symbol_size = op.modi_col(1)# use next column to Y as symbol size
    plot.symbol_kind = op.modi_col(2)

◆ ocolor()

originpro.utils.ocolor ( rgb)
convert color to Origin's internal OColor

Parameters:
    rgb: names or index of colors supported in Origin.
                  name          index    (Red, Green, Blue)
                  'Black'           1       000,000,000
                  'Red'             2       255,000,000
                  'Green'           3       000,255,000
                  'Blue'            4       000,000,255
                  'Cyan'            5       000,255,255
                  'Magenta'         6       255,000,255
                  'Yellow'          7       255,255,000
                  'Dark Yellow'     8       128,128,000
                  'Navy'            9       000,000,128
                  'Purple'          10       128,000,128
                  'Wine'            11      128,000,000
                  'Olive'           12      000,128,000
                  'Dark Cyan'       13      000,128,128
                  'Royal'           14      000,000,160
                  'Orange'          15      255,128,000
                  'Violet'          16      128,000,255
                  'Pink'            17      255,000,128
                  'White'           18      255,255,255
                  'LT Gray'         19      192,192,192
                  'Gray'            20      128,128,128
                  'LT Yellow'       21      255,255,128
                  'LT Cyan'         22      128,255,255
                  'LT Magenta'      23      255,128,255
                  'Dark Gray'       24      064,064,064
         it can be in formmat as well, for example, '#f00' for red.
         when the input is a tuple, it should be
         if rgb is tuple of intergers between 0 and 255,
         the color is set by RGB (Red, Green, Blue).

Returns:
    (int) OColor
Example:
    print(op.ocolor('Gray'))

◆ olab_download()

originpro.utils.olab_download ( file)
download a file from Originlab website with blocking so
function will not return until it is done or encountering an error
Parameters:
    file (str or int): file name with extention or the fid,
                       which you can find out from Template Center
Returns:
    0 if downloaded
    1 if already downloaded and nothing to do
    <0 error
Examples:
    n=op.olab_download('RaisedReliefMap.otpu')
    n=op.olad_download(939)

◆ org_ver()

originpro.utils.org_ver ( )
Parameters:
    none
Returns:
    Origin Version as float
Examples:
    print(op.org_ver())

◆ origin_class()

originpro.utils.origin_class ( name)
Get Origin base class
Parameters:
    name(string):Origin class name
Returns:
     Origin base class
Examples:
    ranges=op.origin_class('DataRange')

◆ path()

originpro.utils.path ( type = 'u')
Returns one of the Origin pre-defined paths: User Files folder, Origin EXe folder,
project folder, Project attached file folder.

Parameters:
    type (str): 'u'(User Files folder), 'e'(Origin Exe folder), 'p'(project folder),
                'a'(Attached file folder), 'c'(Learning Center)

Returns:
    (str) Contains folder path

Examples:
    uff = op.path()
    op.open(op.path('c')+ r'Graphing\Trellis Plots - Box Charts.opju')

◆ set_lt_str()

originpro.utils.set_lt_str ( vname,
value )
sets a LabTalk string variable value.
Parameters:
    vname(string):LabTalk variable name
    value:
Returns:
    bool value that indicate Whether the value is set successfully
Examples:
    fpath = op.file_dialog('*.log')
    op.set_lt_str('fname', fpath)
    tmp=op.get_lt_str('fname')
    print(tmp)
See Also:
    get_lt_str

◆ set_lt_var()

originpro.utils.set_lt_var ( name,
value )
sets a LabTalk numeric variable value. This is usually used for setting system variables
Parameters:
    name(string):LabTalk numeric variable name
    value:
Return:
    none
Example:
    op.set_lt_var("@IAS",5)#set import using multi-thread for files 5M or larger
See Also:
    lt_float, set_lt_str

◆ set_show()

originpro.utils.set_show ( show = True)
Show or Hide the Application
Parameters:
    show(bool):
Return:
    none
Example:
    op.get_show()

◆ to_rgb()

originpro.utils.to_rgb ( orgb)
convert an Origin OColor to r, g, b

Parameters:
    orgb(int): OColor from Origin's internal value

Returns:
    (tuple) r,g,b
Example:
    print(op.to_rgb(20))#128,128,128

◆ wait()

originpro.utils.wait ( type = 'r',
sec = 0 )
Wait for recalculation to finish or a specified number of seconds.

Parameters:
    type (str): Either 'r' to wait for recalculation to finish or
                's' to wait for specified seconds
    sec (float): Number of seconds to wait is 's' specified for type

Returns:
    None

Examples:
    op.wait()#wait for Origin to update all the recalculations
    op.wait('s', 0.2)#gives 0.2 sec for graphs to finish updating