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,
- From PTC Mathcad, open online help (F1). Alternatively, you can reach online help from a web browser by clicking here.
- 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 image below shows examples that can be found in the API Guide (see image below) as well within Mathcad’s installation pack.
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.
Check out the steps below:
- Download the example here: C#_GraphMat.
- To run the example, execute GraphMatrix.exe. The GraphMat dialog opens. All input fields are disabled.
- Click File > Open to open the Force Google Graph.mcdx worksheet. When this worksheet opens, the GraphMat input fields become enabled.
- 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.
- 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.
- 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.
- 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.
- 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.
Get Personalized Help
More questions about the API and SDK? Reach out to a Mathcad expert