cancel
Showing results for 
Search instead for 
Did you mean: 
cancel
Showing results for 
Search instead for 
Did you mean: 

Community Tip - Did you know you can set a signature that will be added to all your posts? Set it here! X

Mathcad Prime Interface / API

ashah1
6-Contributor

Mathcad Prime Interface / API

Hello,

 

I'm developing a custom application that communicates to Mathcad Prime. I would like to ask few questions related to Mathcad Prime Interface as below:

 

  1. Is there any database used by MC15 or MCP?
  2. What are the interfaces / APIs available to integrate with a custom solution?
  3. What language these APIs are developed? Are there any C# .Net interfaces available?
  4. What would be the cost of SDK? and is it a bulk license or one license per developer?

Kindly share your inputs.

 

Thanks & Regards,

Ashish

6 REPLIES 6
LucMeekes
23-Emerald III
(To:ashah1)

1. What do you mean by 'database used'? Almost every serious computer program uses a database of some sort. If not for functional reasons, then at least for administrative purposes, internally. You can think of the MuPad library of symbolic functions, bundled with Prime, as a database. Would you be able to access and/or manipulate that database via the API...? I think NOT.

2. There is an API available.

3. Since Prime is programmed in .Net, I would assume that you talk from .Net to the API.

4. The SDK, if you are referring to the suite of documentation of the API with examples of how to use it, is expensive. I seem to remember $5k. No, found it... it's $9k  per company. Read this:

https://community.ptc.com/t5/PTC-Mathcad/NEW-API-for-Mathcad-Prime-3-1/m-p/12388#M4769

 

Success!

Luc

Hi,

 

Followed the discussions on your link.  Lots of complaints about the 9k.

Files are now:

Ptc.MathcadPrime.Automation.dll
Ptc.MathcadPrime.Automation.tlb

D:\Program Files\Mathcad Prime 5.0.0.0 

 

You can read the tlb file in Visual Studio Community 2015 like the discussion said to examine the objects, methods etc.

 

Cheers

Hi,

 

  1. Is there any database used by MC15 or MCP?'

MCP has a "database" of input and output regions declared in a worksheet.  Each input output has an "alias" in the database used to communicate data.  You can manually change the names of aliases.

Capture2.JPG

 

2. What are the interfaces / APIs available to integrate with a custom solution?

 

Two file are included in the Prime distribution

Ptc.MathcadPrime.Automation.dll

Ptc.MathcadPrime.Automation.tlb.

Using Visual Studio 2017 Community you "add a reference" to a project.  Select Project | Add a Reference.  select the COM section from the left hand menu.  Use the Browse button go to the Mathcad Prime distribution and select the dll file.  This will add the dll and tlb to the project and more importantly gives you intellisense on using the classes in the IDE and the classes are available in the object browser.

 

3. What language these APIs are developed? Are there any C# .Net interfaces available?

 

You can use in Visual Studio 2017 Community either Visual Basic or C# to program.  Enclosed here is the visual C# that inputs and outputs to Mathcad both doubles and matrices of doubles

Capture.JPG

using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using System.Windows.Forms;
using Ptc.MathcadPrime.Automation;

namespace mathcad3
{
public partial class Form1 : Form
{

 

public Form1()
{
InitializeComponent();
}

 

/// <summary>
///
/// </summary>
/// <param name="sender"></param>
/// <param name="e"></param>
private void button1_Click_1(object sender, EventArgs e)
{
var appCreate = new ApplicationCreatorClass();
ApplicationCreator app;
app = (ApplicationCreator)appCreate;
IMathcadPrimeWorksheet3 ws;
ws = (IMathcadPrimeWorksheet3)app.Open(@"D:\\Prime\\VB\\Test.mcdx");

app.Visible = true;
double output;

IMathcadPrimeWorksheet wsTest = app.ActiveWorksheet;
ws = (IMathcadPrimeWorksheet3)wsTest;

wsTest.SetRealValue("B", 22.5, "");

IMathcadPrimeOutputResult resolve = wsTest.OutputGetRealValue("out");
output = resolve.RealResult;
textBox1.Text = output.ToString();

int i = 5;
IMathcadPrimeMatrix matrixValue = (IMathcadPrimeMatrix)ws.CreateMatrix(3, 3);

i = matrixValue.SetMatrixElement(0, 0, 2.5);
i = matrixValue.SetMatrixElement(0, 1, 4.0);
i = matrixValue.SetMatrixElement(0, 2, 3.1);
i = matrixValue.SetMatrixElement(1, 0, 1.5);
i = matrixValue.SetMatrixElement(1, 1, 3.6);
i = matrixValue.SetMatrixElement(1, 2, 5.0);
i = matrixValue.SetMatrixElement(2, 0, 7.2);
i = matrixValue.SetMatrixElement(2, 1, 4.8);
i = matrixValue.SetMatrixElement(2, 2, 6.8);

ws.SetMatrixValue("M", matrixValue, "");

IMathcadPrimeOutputMatrixResultAs hereResult = ws.OutputGetMatrixValueAs("here", "");
double wshereResultRowsCount = hereResult.MatrixResult.Rows;
double wshereResultColsCount = hereResult.MatrixResult.Columns;

double dblhere;

for (int ic = 0; ic < wshereResultRowsCount; ic++)
{

for (int jc = 0; jc < wshereResultColsCount; jc++)
{
hereResult.MatrixResult.GetMatrixElement(ic, jc, out dblhere);
richTextBox1.AppendText(Convert.ToString(dblhere));
richTextBox1.AppendText(", ");

}
richTextBox1.AppendText("\n");

}

 

((IMathcadPrimeWorksheet3)ws).Close(SaveOption.spPromptToSaveChanges);
System.Runtime.InteropServices.Marshal.ReleaseComObject(ws);
app.CloseAll(SaveOption.spDiscardChanges);
app.Quit(SaveOption.spDiscardChanges);
System.Runtime.InteropServices.Marshal.ReleaseComObject(app);
System.Runtime.InteropServices.Marshal.ReleaseComObject(appCreate);
}
}
4. What would be the cost of SDK? and is it a bulk license or one license per developer?

Why spend the $9k for the examples.   The intellisense feature of Visual Studio and the object browser gives you all the classes etc.  Above is a simple example that works.  There are a number of other examples available in this forum and on the www.

 

Cheers

Terry

 

JW1
4-Participant
4-Participant
(To:terryhendicott)

Dear specialist,

 

I love this post. I am also attempting to exchange the information between python and mathcad. Contrary to the post, there may be no python scripts to deal with it. As you may or may not know, there is a python wrapper named mathcadPy. It has mostly worked well but some functionalities do not work at all. Especially, there are SetMatrixElement, .GetMatrixElement and SetMatrixValue as in C++.

 

Followings are the parts of equivalent function in python:

----------------------------------

    def set_element(self, row_index, column_index, value):
        """ Sets the value of an element in the Matrix """
        if self.object is not None:
            try:
                row, col = int(row_index), int(column_index)
                self.object.SetMatrixElement(row, col, value)
            except ValueError:
                raise ValueError("Matrix maths can only use numerical values")
            except:
                raise Exception("COM Error setting element value")  # Hidden for above @FIXME
        else:
            raise TypeError("Matrix must first be created")

 

JW1
4-Participant
4-Participant
(To:terryhendicott)

Dear specialist,

 

I love this post. I am also attempting to exchange the information between python and mathcad. Contrary to the post, there may be no python scripts to deal with it. As you may or may not know, there is a python wrapper named mathcadPy. It has mostly worked well but some functionalities do not work at all. Especially, there are SetMatrixElement, .GetMatrixElement and SetMatrixValue as in C++.

 

See github at https://github.com/JIMMY-KSU/MathcadPy. Original developer does not improve it any more. I hope you enjoy this.

 

Followings are the parts of equivalent function in python:

----------------------------------

    def set_element(self, row_index, column_index, value):
        """ Sets the value of an element in the Matrix """
        if self.object is not None:
            try:
                row, col = int(row_index), int(column_index)
                self.object.SetMatrixElement(row, col, value)
            except ValueError:
                raise ValueError("Matrix maths can only use numerical values")
            except:
                raise Exception("COM Error setting element value")  # Hidden for above @FIXME
        else:
            raise TypeError("Matrix must first be created")

 

Connor632
3-Newcomer
(To:ashah1)

The API is built in to Prime. The SDK, you have to pay for (a ridiculous amount of money too). As far as I know, it works in the trial version. What are you trying to do?

Announcements

Top Tags