Written by Vipul Trivedi
  • 1/23/2025
  • Read Time : 6 min.

How to Add Triggerable Events with Button Advanced Controls

click here to learn about push button advanced controls in PTC Mathcad Prime

Editor’s Note: This blog is based on a PTC Mathcad Prime 10 worksheet. Download the accompanying Button worksheet here. If you do not have a Mathcad Prime 10 worksheet viewer, download our free 30-day trial here.

The Button scriptable control in PTC Mathcad Prime 10 is a powerful tool for capturing user input through button selection and de-selection. While push buttons typically return a binary value of 1 or 0 (on or off), their behavior can be significantly enhanced through scripting, utilizing the Button class and other scripting language features. This blog explores the sophisticated capabilities of the Button control, its customization options, and the event-driven programming model that underpins its functionality.

Inserting & Event-Driven Programming with the Button Control

Creating a Button Control

To create a push button control in Mathcad Prime 10:

  1. Navigate to the "Input/Output" tab’s "Controls" section
  2. Select "Button" and place it in your worksheet where you want the options to appear.

Default Script of Buttons

The default script for a Button control includes four key events: Start, Exec, Stop, and Click. Each of these events serves a specific purpose in the button’s lifecycle and interaction model:

  1. Start: This event is ideal for initializing the button and setting its formatting properties. It runs when the script is first executed and sets up the initial state of the button.
  2. Exec: In this event, inputs and outputs are processed, including returning the state of the button. It handles the core logic of the button’s functionality.
  3. Stop: This event is used for cleanup and finalization tasks when the script is terminated.
  4. Click: The most crucial event for push buttons, the Click event handles state changes and re-executes the control after the user interaction. This is where the button's logic responds to user input, ensuring that the appropriate actions are taken based on the button's new state.
Default Script Editor and Properties of Button Advanced Control Mathcad Prime 10

The script can be written in either JScript or VBScript. However, please note that VBScript will be deprecated in a future Mathcad Prime release. Therefore, all the scripting in this worksheet has been implemented using JScript.

By default, push buttons provide basic functionality, but behavior can be extensively customized:

  • Naming Convention: The button’s text (name) can be altered by right clicking the button and selecting Edit > Properties. Alternatively, formatting properties can be set through scripting, offering greater flexibility and control. Note that settings applied via the script will override those made in the Properties dialog.
  • Dual-State Appearance: While the Properties tab allows changes to a single state setting, scripting is required to program appearance effects for both states of the button. This enables dynamic visual feedback based on the button’s state.

Button Worksheet Examples Overview

In this example, we have a Mathcad Prime 10 worksheet featuring three push buttons, each designed to perform a specific task. You can read along the explanations below, and/or watch the embedded video about this same worksheet to follow along. Note that since the video was produced, Button 1 has been edited to allow the user to input the location of the web content they would like to copy with a Text Box control, as opposed to the original functionality where the URL was hard-coded into the Button's Script Editor.

Push Button 1: Web Content Copier and Word Manipulator

  • Functionality: This push button links to a script that automates the process of copying content from a specified webpage (including PDFs) and pasting it into a Word document. After pasting the content, the same push button provides the option to close the Word application.
  • Script Overview: The script for this push button utilizes web scraping techniques to extract content from the webpage and the Microsoft Word Interop library to handle Word document manipulation.
  • Benefits: This push button significantly reduces the time and effort required to transfer information from the web to Word, automating repetitive tasks and ensuring accuracy.
Mathcad Prime 10 Open Word Button Advanced Control copy web page into Microsoft Word document

Clicking Open Word opens Microsoft Word and scrapes the contents of the URL put in the yellow Text Box.

Push Button 2: Recalculate Worksheet

  • Functionality: This push button recalculates the entire Mathcad worksheet, ensuring that all calculations are updated based on the latest input values.
  • Script Overview: The script linked to this push button calls the worksheet's recalculation function, updating all results and outputs.
  • Benefits: Ensures that users always have the most up-to-date calculations, improving accuracy and reliability of the worksheet data.

Push Button 3: Save Worksheet

  • Functionality: This push button saves the current state of the Mathcad worksheet, preserving all changes and updates.
  • Script Overview: The script for this push button triggers the worksheet save function, ensuring all work is saved securely.
  • Benefits: Provides a quick and easy way to save progress, preventing data loss and ensuring that all changes are preserved.

Benefits of Using Push Buttons

Simplicity and Clarity: Automating repetitive tasks with push buttons saves time and effort, allowing users to focus on more critical aspects of their work.

Streamlined Workflow: Push buttons make Mathcad worksheets more interactive and user-friendly, improving the overall user experience.

Dynamic Interactivity: Automation reduces the risk of human error, ensuring that tasks are performed accurately and consistently.

Customization: Push buttons facilitate seamless integration with external applications (Microsoft Word in this case), extending the functionality of Mathcad worksheets.

Push Button Conclusions

Push buttons are powerful tools that enhance the interactivity, efficiency, and functionality of worksheets. By automating tasks such as web content copying, worksheet recalculation, and saving, push buttons enable users to streamline their workflow and improve productivity. The practical application of these push buttons in a Mathcad worksheet demonstrates their versatility and utility in real-world scenarios.

Incorporating push buttons into your Mathcad Prime 10 worksheets can transform the way you work, making complex tasks simpler and more efficient. Whether you are automating web content transfers, recalculating worksheets, or saving your progress, push buttons provide a powerful solution to enhance your productivity and accuracy.

If you’re interested in learning more about the Advanced Control Button Class, Button Format Properties, Button Events, and Example, then you may consult the Help documentation provided online and also inside the software.


Advanced Controls Crash Course

Learn more about use cases for all of the Advanced Controls by attending our free, on-demand training event: the Advanced Controls Crash Course!

Tags:

How to Add Triggerable Events with Button Advanced Controls
Learn how to use the Button Advanced Control in PTC Mathcad Prime, which allows for interactive trigger events, with a downloadable sample worksheet.