Written By Guest Author
  • 12/30/2021
  • Read Time : 3 min.

Getting Started with the PTC Mathcad API

API abstract.

Guest Post by Ioana Cernat

This article provides an overview of the PTC Mathcad application programming interface (API) and its software development kit (SDK).

To find the SDK,

  1. From PTC Mathcad, open online help (F1). Alternatively, you can reach online help from a web browser by clicking here.
  2. Click Integrating with other products > API Guide.

What Can You Do with the API?

The API provides a mechanism for communicating with Mathcad from another Windows application, including a customer stand-alone application that users write. The API consists of a group of automation classes that you can use to do the following (just to mention a few):

  • Open Mathcad
  • Calculate the results
  • Assign and retrieve variables, matrices, and strings
  • Control the appearance of windows
  • Retrieve information about regions
  • Save, print, or close the Mathcad worksheet
  • Close Mathcad entirely
If you want, you can even send data or assign variable values to PTC Mathcad Prime from another application (such as Google Graphs) or send results back to the original application.

Hence, using the automation commands, you can execute numerous tasks - from easier to more complex ones.

Intro to the SDK

The SDK contains a user guide that includes documentation about the automation commands and API examples that can help you better understand how to use and create your custom applications. Depending on your programming skills, you can use one of the following programs: C++, C#, VB, VBScript or JavaScript.

The image below shows examples that can be found in the API Guide (see image below) as well within Mathcad’s installation pack.

Code examples in the software development kit.

Image: Location of code examples within the Mathcad SDK.

Next, let’s look closer one of the examples.

Example 10: GraphMat

This example demonstrates in C# how to launch PTC Mathcad Prime, load a worksheet, push scalar values to the worksheet, compute the worksheet, and pull back a matrix result. It uses .NET APIs, PTC Mathcad PrimeAPIs, and Google Charts APIs to create a solution.

Graphmat example in the Mathcad SDK.


Check out the steps below:

  1. Download the example here: C#_GraphMat.
  2. To run the example, execute GraphMatrix.exe. The GraphMat dialog opens. All input fields are disabled.
  3. Click File > Open to open the Force Google Graph.mcdx worksheet. When this worksheet opens, the GraphMat input fields become enabled.
  4. In the open worksheet, note the four input regions at the top of the second page, and the two output regions at the bottom of the third page.
  5. In the GraphMat dialog, you can modify any of the four text boxes before clicking Send input values to send the values to the worksheet.
  6. In the worksheet, the four input regions now reflect the values you set in the GraphMat dialog. Mathcad Prime recalculates the worksheet and sends the values of SForce and outstring to the GraphMat dialog as a chart and a string of numbers displayed below the graph. To meet Google Charts limitations, the Force vector is scaled to generate SForce to ensure that the range of its elements is 0-100.
  7. For the next calculation, set new diameter or engine values, then click Send input values. The graph and the string of numbers are updated accordingly.
  8. In PTC Mathcad Prime, click File > Close, and then in GraphMat dialog click File > Exit.
You could override the initial Mathcad values by inserting new values in the existing fields. You will see everything getting updated in an instant in the Mathcad worksheet once you send the information to Mathcad from the interface.

Once you have Mathcad installed, you can access these examples in the installation folder and open the code to inspect it, learn from it, create a new one based on an the already existing ones, and bring your own customized inputs and information. Then, from the moment you compile the code, the system provides you with the appropriate interface.

For an alternative example with a JavaScript demo, watch the video below:

 

 

 

Get Personalized Help

More questions about the API and SDK? Reach out to a Mathcad expert

Tags:

About the Author

Product Lifecycle Report guest authors are industry thought leaders on topics and insights related to the IoT. If you are interested in becoming a guest author, please contact Michelle Hopkins at mihopkins@ptc.com.


Getting Started with the PTC Mathcad API
The API provides a mechanism for communicating with Mathcad from another Windows application. Here's how you can use it for your integrations.