### Example: instOPX myopx; Source: https://docs.originlab.com/x-function/ref/instopx Example command to install an OPX package whose name is 'myopx'. ```origin instOPX myopx; ``` -------------------------------- ### Example: instOPX; Source: https://docs.originlab.com/x-function/ref/instopx Example command to install an OPX package whose name is the system variable fname$. ```origin instOPX; ``` -------------------------------- ### OrgApps::InstalledApps Source: https://docs.originlab.com/originc/ref/orgapps-installedapps Gets the collection of installed apps. This property is public and returns a Collection (though the example uses OrgAppInfo). ```APIDOC ## OrgApps::InstalledApps ### Description The collection of installed apps. ### Declaration ``` Collection InstalledApps ``` ### Access Type public ### Header to Include origin.h ### Example ``` void OrgApps_InstalledApps_ex1() { foreach(OrgAppInfo app in OrgApps.InstalledApps) { if (app.ID <= 0) continue; printf("[ID: %d]\r\n", app.ID); printf(" Name: %s\r\n", app.Name); } } ``` ``` -------------------------------- ### Get property values (page.name$, layer.x.from) Source: https://docs.originlab.com/labtalk/guide/lt-objs Shows how to retrieve property values. Text properties are retrieved with the $ suffix, while numeric properties are retrieved without it. The example gets the active page name and the start value of the x-axis. ```LabTalk pn$ = page.name$; // Get that active page name layer.x.from = ; // Get and display the start value of the x-axis ``` -------------------------------- ### Get first visible row index with wks.GetNextVisibleRow Source: https://docs.originlab.com/quick-help/get-visible-row-index Returns the first visible row index starting from row 0. In the example, it returns 38 because rows 1-37 are hidden. ```LabTalk wks.GetNextVisibleRow(0)= ``` -------------------------------- ### CreateProcess example launching notepad.exe Source: https://docs.originlab.com/originc/ref/createprocess Example EX1 shows how to call CreateProcess to launch notepad.exe maximized. It initializes STARTUPINFO and PROCESS_INFORMATION structures, sets STARTF_USESHOWWINDOW and SW_SHOWMAXIMIZED, and passes CREATE_DEFAULT_ERROR_MODE. The return value is stored in bSucess. ```cpp void test_create_process() { STARTUPINFO sinfo; PROCESS_INFORMATION pinfo; memset(&sinfo, 0, sizeof(STARTUPINFO)); memset(&pinfo, 0, sizeof(PROCESS_INFORMATION)); // test control wShowWindow sinfo.dwFlags = STARTF_USESHOWWINDOW; sinfo.wShowWindow = SW_SHOWMAXIMIZED; BOOL bSucess = CreateProcess("C:\\Windows\\notepad.exe", NULL, NULL, NULL, FALSE, CREATE_DEFAULT_ERROR_MODE, NULL, NULL, &sinfo, &pinfo); } ``` -------------------------------- ### Initialization file example Source: https://docs.originlab.com/quick-help/deploy-sr-silently/de Example initialization file that sets %AppFolder% to the Origin program folder at C:\Program Files\OriginLab\Origin 85\. ```text [Variables] %AppFolder%=C:\Program Files\OriginLab\Origin 85\ ``` -------------------------------- ### Get cell value - PyOrigin Datasheet::Cell example Source: https://docs.originlab.com/python/pyorigin/classes/datasheet-cell Example EX1: Get the value from a Datasheet cell using the Cell method. Use FindWorksheet to get the worksheet, then call Cell(row, col) with 0-based indices. The example prints the value at column 3, row 2. ```python import PyOrigin wks=PyOrigin.FindWorksheet('Book1') #Get the value in cell print('the number in col(3)[2] is %f' % wks.Cell(1,2)) ``` -------------------------------- ### OriginApp example: open project and find objects Source: https://docs.originlab.com/originc/ref/originapp/ja Launches a new Origin instance, opens a sample project, and uses the finder object to search for 'Time' and collect metadata. Requires including OriginApp.h. The example prints results using out_tree. ```cpp #include <..\Originlab\OriginApp.h> void OriginApp_ex() { OriginApp oa; if (0 != oa.Open(GetAppPath(TRUE) + "Samples\\Data Manipulation\\Setting Column Values.opj") ) return; Object finder = oa.GetFinder(); if ( finder ) { finder.Locations = (FINDOBJECT_COLUMN|FINDOBJECTCNTRL_PROJECT); // FINDOBJECT_MASK for all finder.Options = (FINDMETADATACNTRL_MATCH_WHOLE_WORD|FINDMETADATACNTRL_LONG_NAME|FINDMETADATACNTRL_SHORT_NAME|FINDMETADATACNTRL_COMMENTS|FINDMETADATACNTRL_ONE_INFO_VARIABLE); Tree trResults; int nCount = finder.Find("Time"); for ( int ii = 0; ii < nCount; ii++ ) { Object obj; obj = (finder.GetObject(ii)); TreeNode trResult; trResult = trResults.AddNode("obj"+(ii+1)); string strRange = obj.Range; trResult.AddTextNode(strRange, "Range"); string strPEPath = obj.PEPath; trResult.AddTextNode(strPEPath, "PEPath"); string strType = obj.TypeName; trResult.AddTextNode(strType, "Type"); string strName = obj.Name; trResult.AddTextNode(strName, "Name"); string strLongName = obj.LongName; trResult.AddTextNode(strLongName, "LongName"); if ( strType == "GraphPage" ) { string strImageFile("D:\\Working\\test.png"); bool bPreview = obj.Preview(strImageFile); if ( bPreview ) trResult.AddTextNode(strImageFile, "Preview"); } _VARIANT v = finder.GetMetadata(ii); DWORD dwMetaDataFound = v;// in this case, it's FINDMETADATACNTRL_LONG_NAME trResult.AddNumericNode(dwMetaDataFound, "Attributes"); _VARIANT v2 = finder.GetMetadataValue(ii); string strXML; strXML = v2; Tree tree; tree.SetString(strXML); TreeNode trMetadatas = trResult.AddNode("Metadatas"); trMetadatas.Replace(tree, true, true); } out_tree(trResults); } } ``` -------------------------------- ### strlen example: get string length Source: https://docs.originlab.com/originc/ref/strlen Example function that creates a string and uses strlen to get its length, then outputs the length using out_int. ```c void strlen_ex1() { string str1 = "Hello World!"; int len = strlen(str1); // len is 12 (the length of str1). out_int("The length is ", len); } ``` -------------------------------- ### Example: dump_drivers using okutil_get_installed_ODBC_drivers Source: https://docs.originlab.com/originc/ref/okutil_get_installed_odbc_driver Example code that includes Origin.h and outils.h, declares a vector, calls okutil_get_installed_ODBC_drivers, and prints each driver name using printf. ```cpp #include #include void dump_drivers() { vector vs; int num = okutil_get_installed_ODBC_drivers(&vs); for (int i = 0; i < num; i++) { printf("%s\n", vs[i]); } } ``` -------------------------------- ### Example: Get and display root folder name Source: https://docs.originlab.com/originc/ref/project-rootfolder Example function run_Project_RootFolder that retrieves the root folder via Project.RootFolder, gets its name with GetName(), and displays it using out_str(). ```origin-c void run_Project_RootFolder() { // Get the root folder: Folder fld = Project.RootFolder; // Get the name: string strRoot = fld.GetName(); // Display the name: out_str(strRoot); } ``` -------------------------------- ### Save, New, and Open a Project with Project.Save and Project.Open Source: https://docs.originlab.com/originc/guide/managing-projects Saves the current project to a specified path, starts a new project, and opens a saved project. The path is provided as a string literal. ```Origin C string strPath = "c:\\abc.opj"; // Project path and name Project.Save(strPath); // Save current project Project.Open(); // Start a new project Project.Open(strPath); // Open saved project ``` -------------------------------- ### Get page by index with op.get_page() Source: https://docs.originlab.com/originpro/namespaceoriginpro_1_1project.html Gets a page (WBook, MBook, GPage, IPage) by index. The example gets the first workbook. ```python w=op.get_page('w', 0)//there should a workbook exist ``` -------------------------------- ### Python Example: Create and Navigate Folders with RootFolder Source: https://docs.originlab.com/com/classes/application/rootfolder Python example using OriginExt to create folders from the root, activate a folder by path, add graph and worksheet pages, and restore the original active folder. ```Python import OriginExt as O app = O.Application(); app.Visible = app.MAINWND_SHOW # Save the current folder fldOld = app.ActiveFolder pathActive = fldOld.Path # Create a new folder named "Testing" and sub folders app.RootFolder.Folders.Add("Testing").Folders.Add("Private").Folders.Add("Some Graphs") # Activate the folder "Graphs" fldr = app.RootFolder.Folders.FolderFromPath("Testing\\Private\\Some Graphs") fldr.Activate() # Add a new Graph to the new folder app.GraphPages.Add("origin") # Get the parent level folder f2 = fldr.Parent fldr = f2.Folders.Add("Some Worksheets") fldr.Activate() # Add a new Workbook to the new folder app.WorksheetPages.Add("origin") fldr = app.RootFolder.Folders.FolderFromPath(pathActive) # restore active folder app.ActiveFolder = fldOld ``` -------------------------------- ### impinfo example: get file count and file info Source: https://docs.originlab.com/x-function/ref/impinfo Example script that uses impinfo to get the file count for a workbook, then loops through each file to retrieve and display its file path and name. ```LabTalk impinfo ipg:=[Book2] findex:=0 fcount:=MyCount; // Just to get the file count // Now loop for each file loop(idx,1,MyCount) { impinfo ipg:=[Book2] findex:=idx trInfo:=MyTree; str1$ = MyTree.Info.FilePath$; str2$ = MyTree.Info.FileName$; ty File $(idx): %(str1$)%(str2$); } ``` -------------------------------- ### Example: download_palette_ex Source: https://docs.originlab.com/originc/ref/download_palette Example usage of download_palette. It constructs a URL, prepares a local file path, calls the function, and prints the result. ```cpp #include <..\originlab\palette_utils.h> void download_palette_ex() { //online palette file url string strURL = "https://www.benjaminmoore.com/-/media/sites/benjaminmoore/files/palettedownloads/ase/en-us/benjaminmoore_off-whitecolors_en-us.ase"; //prepare local file string strPALFile = GetAppPath() + GetFileName(strURL, true)+".pal"; //download the online file and save it as .pal file int nRet = download_palette(strURL, strPALFile); if(0 == nRet) printf("online file:\n%s\nis saved as:\n%s\n", strURL, strPALFile); else out_str("fail"); } ``` -------------------------------- ### ActivateFolder example Source: https://docs.originlab.com/originc/ref/project-activatefolder Example showing how to activate a subfolder named 'MySub' in the project's root folder. Requires the root folder to be active and the subfolder to exist. Prints success or failure message. ```cpp // For this example to run, create a subfolder named "MySub" in the project's root folder. // Make sure that the root folder is active. // After the function executes, "MySub" will be the active folder. void Project_ActivateFolder_ex1() { string strPath = "/MySub"; if (Project.ActivateFolder(strPath)) out_str("Folder activation succeeded."); else out_str("Folder activation failed!"); } ``` -------------------------------- ### OriginVer Usage Example Source: https://docs.originlab.com/python/pyorigin/global-functions/originver Example of importing PyOrigin, calling OriginVer to get the version, and printing it. ```python import PyOrigin Version=PyOrigin.OriginVer() print(Version) ``` -------------------------------- ### GetLength example Source: https://docs.originlab.com/labtalk/ref/getlength-func Example usage of GetLength to get the length of the string "origin.ini". ```labtalk len = GetLength("origin.ini") ``` -------------------------------- ### Project::Open examples: normal open, append, and append with new folder Source: https://docs.originlab.com/originc/ref/project-open Three functions demonstrate Project::Open with different options: OPJ_OPEN_NORMAL (default), OPJ_OPEN_APPEND, and OPJ_OPEN_APPEND_NEW_FOLDER. Each checks the return value and prints a success or failure message. The path must be a full path with .opj extension. ```cpp // For this example to run, make sure that the variable strPathName inside // the function is initialized to the pathname of an existing project file. void Project_Open_Ex1() //Open a new project { string strPathName = "c:\\myproject.opj"; if (Project.Open(strPathName)) out_str("Project opening succeeded."); else out_str("Project opening failed!"); } void Project_Open_Ex2() //Append myproject.opj to the current project. Use current folder as root to append all contents. { string strPathName = "c:\\myproject.opj"; if (Project.Open(strPathName, OPJ_OPEN_APPEND)) out_str("Project appending succeeded."); else out_str("Project appending failed!"); } //OPJ_OPEN_APPEND_NEW_FOLDER void Project_Open_Ex3() //Append myproject.opj to the current project. Use OPJ filename to create a subfolder in current folder { string strPathName = "c:\\myproject.opj"; if (Project.Open(strPathName, OPJ_OPEN_APPEND_NEW_FOLDER)) out_str("Project appending succeeded."); else out_str("Project appending failed!"); } ``` -------------------------------- ### Example URL with path components Source: https://docs.originlab.com/origin-help/connect-to-web Example URL with path components that can be broken down into parts for advanced configuration. ```text https://pubchem.ncbi.nlm.nih.gov/rest/pug/compound/cid/2244 ``` -------------------------------- ### get -csfi Source: https://docs.originlab.com/labtalk/ref/get_options_for_data_plots/ja Gets the starting color index when the symbol fill color is set as Increment. ```APIDOC ## get -csfi ### Description If the symbol fill color is set as **Increment**, get the starting color index. ### Syntax get _name_ **-csfi** _[variableName]_ ### Parameters - **name** - The name of the plot or object. - **variableName** (optional) - The variable to store the result. ### Returns The starting color index. ``` -------------------------------- ### VB Example: Display OrgVersion Source: https://docs.originlab.com/com/classes/projectinfo/orgversion VB example that creates an Origin application instance, retrieves the ProjectInfo object, and displays the OrgVersion value in a message box. ```VB Sub ProjectInfo() Dim app As Origin.IOApplication Dim pi As Origin.ProjectInfo app = New Origin.ApplicationSI pi = app.ProjectInfo() MsgBox(pi.OrgVersion.ToString()) End Sub ``` -------------------------------- ### get -pbci Source: https://docs.originlab.com/labtalk/ref/get_options_for_bar_and_column_plots Gets the starting color index when the bar/column border color is set to Increment. ```APIDOC ## get -pbci ### Description If the bar or column border color is set as **Increment**, gets the starting color index. ### Syntax `get _name_ -pbci [variableName]` ### Parameters - `_name_` (string) - Required - The name of the plot or object. - `variableName` (string) - Optional - The variable to store the result. ### Returns - The starting color index (integer). ``` -------------------------------- ### string::GetLength example Source: https://docs.originlab.com/originc/ref/string-getlength Example function string_GetLength_ex1 that creates a string "cow", gets its length (3), empties the string, and gets the length again (0). Outputs the lengths using out_int. ```cpp void string_GetLength_ex1() { string str( "cow" ); int nRet = str.GetLength(); out_int("", nRet);//3 str.Empty(); nRet = str.GetLength(); out_int("", nRet);//0 } ``` -------------------------------- ### Run Image Control Dialog Example Source: https://docs.originlab.com/originc/examples/image-control-dialog Run these commands in the Command window after loading the example file. The first command loads the Origin C file, and the second opens the image preview dialog. Click the UP button to adjust brightness. ```Origin C run.LoadOC(Originlab\ImageControlExample.c, 16); OpenImagePreviewDlg; ``` -------------------------------- ### C# Example: Load and Save Origin Project Source: https://docs.originlab.com/com/classes/application/load C# example that connects to Origin, loads a sample project from the installation folder, and saves it to the User Files Folder. Uses the Load and Save methods. ```C# using Origin; static void LoadAndSaveExample() { // Connect to Origin. Origin.ApplicationSI originApp = new Origin.ApplicationSI(); // The file name of a sample Origin project. string strFileName = "2D Bin and Fit.opj"; // Create the full path of the file for loading and ask Origin to load the project. string strFullFileName = originApp.Path(APPPATH_TYPES.APPPATH_PROGRAM) + "Samples\\Curve Fitting\\" + strFileName; originApp.Load(strFullFileName, System.Type.Missing); // Create the full path of the file for saving and ask Origin to save the project. strFullFileName = originApp.Path(APPPATH_TYPES.APPPATH_USER) + strFileName; originApp.Save(strFullFileName); } ``` -------------------------------- ### ocu_url_encode example: URL encoding and HTTP GET Source: https://docs.originlab.com/originc/ref/ocu_url_encode Example showing how to use ocu_url_encode to encode a search string before appending it to a URL, then perform an HTTP GET request with okutil_http_get and parse the JSON response. ```cpp #include #include void state_search(string strSearch="South Carolina", string strCountry="USA") { //example "http://services.groupkt.com/state/search/IND?text=pradesh" string strURL = "http://services.groupkt.com/state/search/"; strURL += strCountry; strURL += "?text="; ocu_url_encode(&strSearch);//search text might have spaces strURL += strSearch; string result; int err = okutil_http_get(strURL, &result); if( err == 0 ) { Tree tr; JSON.FromString(tr, result); TreeNode trResult = tr.RestResponse; string strRetMsg = trResult.messages._0.strVal; out_str(strRetMsg); if(strRetMsg.Find("No") < 0) out_tree(trResult.result); } else printf("ErrorĀ %d\n", err); } ``` -------------------------------- ### Load datasource.c before running examples Source: https://docs.originlab.com/originc/examples/importing-database Run this command in Origin's script window to load and compile the datasource.c file, which is required before running the database import examples. ```Origin C run.LoadOC(Originlab\datasource.c); ``` -------------------------------- ### DefaultTemplate example EX1 Source: https://docs.originlab.com/originc/ref/defaulttemplate Example EX1: gets the current worksheet template, sets it to "Table", then gets it again with extension, printing both values. Requires including origin.h and defining MAXLINE as 100. ```cpp #define MAXLINE 100 void DefaultTemplate_ex1() { char szTemp[MAXLINE]; DefaultTemplate(szTemp, EXIST_WKS); char szTemp2[MAXLINE]; DefaultTemplate("Table", EXIST_WKS, false); DefaultTemplate(szTemp2, EXIST_WKS, true, true); printf("worksheet template was %s, and has been set to %s\n", szTemp, szTemp2); } ``` -------------------------------- ### Examples for cd X-Function Source: https://docs.originlab.com/x-function/ref/cd Practical examples demonstrating how to refresh the directory view, set specific paths, and capture the working directory into a string variable. ```LabTalk cd ``` ```LabTalk cd c:\c\proj1 ``` ```LabTalk cd "c:\my proj-1" ``` ```LabTalk cd result:=aa ``` ```LabTalk cd "c:\my proj1" aa ``` ```LabTalk cd "" aa ``` -------------------------------- ### CreateObject Example EX1 Source: https://docs.originlab.com/originc/ref/createobject Example EX1 demonstrating how to create an MS Word application object and make it visible. ```cpp void CreateObject_ex1() { Object obj; // Create an MS Word application object: obj = CreateObject("Word.Application"); // Make the application visible obj.Visible = true; } ```