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

Classes

class  _LTTMPOUTSTR
 

Functions

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

Variables

 PATHSEP = os.path.sep
 
def sysvar = _CreateSysVar()
 

Detailed Description

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

Function Documentation

◆ active_obj()

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

◆ attach()

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

◆ color_col()

def 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()

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

◆ evaluate_FDF()

def 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()

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

◆ file_dialog()

def 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()

def 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()

def 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()

def 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()

def 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()

def 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()

def 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()

def 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()

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

◆ lt_exec()

def 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()

def 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()

def 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()

def 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()

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

◆ messagebox()

def 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()

def 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()

def 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()

def 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()

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

◆ origin_class()

def 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()

def 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()

def 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()

def 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()

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

◆ to_rgb()

def 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()

def 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