8.6.4 Associating Script with an Object

Run LabTalk Script from a Text Object

Origin also provides the ability to add a button to a graph or worksheet, and then execute LabTalk script by pushing that button. This allows for script to be saved with a specific project or window.

  1. Press the New Graph button ( Button New Graph.png ) located in the Standard Toolbar to create a new graph.
  2. Press the Text Tool button ( Button Text Tool.png ) in the Tools Toolbar, and then click on the newly created graph and type the text My Button. Then click outside the text to finish editing the text.
  3. Right-click on the text and choose Properties. Click to select the Programming tab.
  4. Set the Script Run After drop-down to Button Up and type the following into the edit box:
  5. type -b "Hello World";
  6. Click OK to close the dialog. Now the text label becomes a button. Click the button. A "Hello World" attention message will pop up.


For more information, see Running LabTalk Script From Graphical Objects

Run Python Script From a Text Object

  1. Create a new workbook.
  2. Select the Text tool Button Text Tool.png from the Tools toolbar to the left side of the project window.
  3. Click on an open space on the worksheet (click in the gray area to the right of the last column). Type Run in the text object and click outside the object. You have now created a label for the button.
  4. Hold down the ALT key while double-clicking on the text object that you just created. The object dialog opens to the Programming tab.
  5. In the lower text box, enter this script:
  6. import pandas as pd
    import originpro as op
    
    data = {'Name':['Tom', 'Jack', 'Mike', 'Alice'],
            'Grade':[99, 98, 95, 90]}
    
    df = pd.DataFrame(data)
    wks = op.find_sheet()
    wks.from_df(df)
  7. From the Script Run After drop-down list, select Button Up, and click OK.
  8. Press the button and import data into the worksheet.
  9. 300px-Python Button.png


For more information, see Running Python from Graphical Objects