5 Create App with User Defined Toolbar Buttons


This tutorial will guide you through creating an app that launches a user-defined toolbar with two buttons. One button removes masked data cells, while the other removes rows containing masked cells, both using LabTalk Script.

Create Folder

To create a folder for the App:

  1. Open Code Builder. In the Workspace tab, right-click the Apps folder.
  2. Select New to create an untitled folder.
  3. Right-click Untitled, choose Rename, and enter Remove Masked Data as the App name.
  4. App RemoveMaskedData.png
  5. Right click on Remove Masked Data, then select Open Folder in File Explorer to view the folder in Windows Explorer. The folder path should be similar to: C:\Users\username\AppData\Local\OriginLab\Apps\Remove Masked Data

Required Files

This simple app will require four files, all of which should be added to the Remove Masked Data after creation.

  • 32×32 pixel icon image for the Apps Gallery.
  • 32x16 pixel bitmap (.bmp) file for the toolbar button, containing two 16×16 pixel images (one for each button).
  • LabTalk script Origin Graph Script (.ogs) file for the code behind the two buttons.
  • Initialization (.ini) file for the toolbar button settings.

Below are detailed steps to create each file

App Icon Image

  1. Right-click the image below and select Save Image As... and save it as Removemask32.png in the app’s folder.
  2. In Code Builder, right click the Remove Masked Data node and select Add Files... and choose RemoveMask32.png to add it.
  3. Expand the node to confirm that the file has been added.
  4. Removemask32.png

Toolbar Button Image

  1. Save the following image as RemoveMaskToolbar.PNG in the app’s folder.
  2. Open it in Paint or another image editor and save as a 16-color Bitmap file named RemoveMaskToolbar.bmp.
  3. In Code Builder, right click the Remove Masked Data node and select Add Files... Choose RemoveMaskToolbar.bmp to add it.
  4. Expand the Remove Masked Data node to confirm that the file has been added.
    Removemasktoolbar.png

LabTalk Script

  1. In Code Builder, right click the Remove Masked Data App node and select New File...
  2. Choose LabTalk Script File as the file type. Enter the file name as RemoveMaskedData and Click OK.
  3. Paste the following text into the newly created file:
    [ClearMaskedCells]
    wreplace find_value:=0/0; //replace all masked cells with missing values
    wcellmask mask:=unmask; //set all masked cell status to be unmasked
    
    [RemoveMaskedRows]
    wreducerows method:=mask; //Call X-Function wreducerows to remove rows with masked cells
  4. Click the Save button.

INI file for the toolbar

  1. In Origin Workspace, choose View: Toolbars...
  2. Navigate to the Button Groups tab and click New... at the bottom.
  3. Set Group Name as: Remove Masked
  4. Set Number of Buttons: 2.
  5. Click Browse..., navigate to the app's folder, and select RemoveMaskToolbar.bmp
  6. App savebuttongroup.png
  7. Click OK.
  8. When the Save As dialog appears, ensure it is saving in the app’s folder. The File Name should be auto-filled.
  9. Click OK.
  10. In the Groups list, select Remove Masked.
  11. Click on the first button.
  12. Click Settings... and set:
  13. File Name: RemoveMaskedData.ogs
  14. Section Name: ClearMaskedCells
  15. Tool Tip Text: Clear data on masked cells
  16. On the right, under Windows, uncheck Matrix, Excel, Graph, Layout (this button should only be active for worksheets).
  17. App clearmaskedcellsbutton.png
  18. Click OK.
  19. Click on second button.
  20. Click Settings... and set:
  21. File Name: RemoveMaskedData.ogs
  22. Section Name: RemoveMaskedRows
  23. Tool Tip Text: Remove rows with masked cells
  24. On the right, under Windows, uncheck Matrix, Excel, Graph, Layout.
  25. App removemaskedrows.png
  26. Click OK.
  27. Click Close to exit the dialog.
  28. Go back to Code Builder, right click the Remove Masked Data node and choose Add Files...
  29. Add Remove Masked.ini to the node.
  30. Expand the Remove Masked Data node to ensure all four files are listed.
  31. App RemoveMaskedData node.png

Generate OPX File

  1. In Code Builder, right click the Remove Masked Data node and select Generate...
  2. In the Package Manager dialog, edit the Package fields such as set Description to: Remove masked cells or rows.
  3. Expand the App node, set Icon to: Removemask32.png.
  4. Set Toolbar Icon to: RemoveMaskToolbar.bmp.
  5. In theLaunch Script field, enter @@TB. This ensures the toolbar button is launched when the app is opened.
  6. Expand the Enable by Window node, only check Workbook (so the app is active only when a worksheet is in use).
  7. Expand the Toolbar node (no need to check it). In the Button Group File field, enter: Remove Masked Data\Remove Masked.ini
  8. App package manager.png
  9. Click File: Save as... menu inside Package Manager
  10. Save it as RemoveMaskedData.OPX under the Documents folder.

Install OPX File

Once the OPX file is generated, you can share it with others who have Origin versions higher than the minimum required version set during generation.

  1. Make sure Origin isn't run as Administrator and no dialog is opened in Origin.
  2. Drag the OPX file from Windows Explorer into Origin
  3. If you drag it into Origin that you used to develop the App, you can click Replace All
  4. Go to Apps Gallery on the right side of Origin workspace. Remove Masked Data app should show there.

Test the App

  1. Open a new workbook and fill it with some data.
  2. Ctrl+select some cells in different columns and use the mask toolbar button to mask them.
  3. Masked cells will turn red and they will be excluded in analysis
  4. Click the Remove Masked Cell app in the Apps Gallery on the right side of Origin workspace.
  5. Remove Masked toolbar button will show.
  6. If you click the 1st button, those masked cells will be cleared with no data.
  7. If you click the 2nd button, rows with masked cells will be removed.

Note: Toolbar launched by App can't be docked in Origin workspace. It will always be floating. You can close the toolbar every time after usage. Click the App button will show the toolbar.