API Guide > Code Examples > Example 7: Send SExpressions
Example 7: Send SExpressions
This example demonstrates, in C#, how to rewrite the definition of a PTC Mathcad Prime input region. The API can rewrite a variable, matrix, or function definition. This code is included in the Form1.cs file.
1. Download the example here: C#.NET_Send_SExpression.
2. To run the example, execute SendSExpr.exe. The Send SExpression dialog window opens:
All input fields are disabled.
3. Click File > Open to open the Graph.mcdx worksheet. When this worksheet opens, the Send SExpression dialog box radio buttons are enabled.
4. In the open worksheet, note the input region that contains the definition f(x):=20. The trace is shown as a horizontal line:
5. In the Send SExpression dialog window:
a. Click any of the radio buttons to send one of the f(x) equations to PTC Mathcad Prime. The f(x) equation you select updates the input region, and the function is rendered as a possible curve fit to the data trace.
b. Select a different radio button and observe the change in the plot. Note that selecting the top radio button provides the best fit.
* 
The radio button callbacks update the input region by sending a string that uses the SetSExprValue method of the worksheet object. To create the string that gets sent to the worksheet:
a. Create the equation in a PTC Mathcad Prime worksheet.
b. Copy the equation to your clipboard.
c. Paste the equation in Notepad.
6. In PTC Mathcad Prime, click File > Close, and then in Send SExpression dialog window click File > Exit.
* 
This example was generated using VS2019 and .NET 4.8.
Was this helpful?