Skip to main content
21-Topaz II
June 28, 2026
Question

A PTC Mathcad Prime XML Writer in C++

  • June 28, 2026
  • 6 replies
  • 132 views

A PTC Mathcad Prime XML Writer in C++

File created with PrimeWriter v1.1 Alpha, an Embracadero RAD Studio 12 C++ Builder program. Program creates a rudimentary worksheet as a starting point.  It is intended for further enhancement to create more elaborate worksheets

Started with a simple request of ChatGPT
"create a PTC Mathcad Prime file that creates variables a and b of 3 and 5 respectively and adds them together for variable c."

This started a week long Monday to Sunday, long hours each day focused chat with chatGPT and has produced a simple programmable worksheet generator in C++. It has some functions already defined; operators +,-,/,* sqrt, sin, cos, tan, exp, pow, nthroot, max, min, atan2, lsolve, concat, det, trace, rank, eigenvals, augment, and submatrix. Adding a new Prime function type only takes two lines of code. So more will be added over time.  Greek symbols can be used.

It is intended as a quick visual report writing method for my C++ FEM work.
The new advantage is C++ program flow can create Prime worksheets with variable content based on that C++ program flow.

C++ statements to create a worksheet are simple once a worksheet ws; variable is established in C++
ws.Define(), ws.Evaluate(), ws.Function(), ws.AddText(), ws.AddHeading(), ws.BlankLine()
Internally within Define() and Function() as parameters to create Prime Equations
Id(), Call(), Paren(), Real(), Str()
Names of Prime mathematical functions capitalised. e.g. Sin() & Operators +, -, *, /.

Matrix library eigen-5.0.0 is linked so Define() can initalise a Prime variable with an Eigen::MatrixXd& directly.

Only XML text is created during the Prime file creation.  Prime does the calculations when file is loaded in Prime.

Willing to share this work.  Also working on a Visual C++ version that is not working fully yet.

 

The files enclosed were generated by the C++ program.  Still needs work on positioning of matrices in the resulting file.

 

Have added a lot of functionality from7_v1 to 8v1b

Milestone 9 is reading values back from the calculated worksheet file.  Already reading doubles but will add vectors and matrices.

 

Cheers

Terry

 

6 replies

5-Regular Member
August 7, 2026

Hi Terry
I am very interested in your initiative. I am trying to do it python, and I think it would not be much different. Obviously I am trying to do this so that AI can write my Mathcad files using information, pdf, images and etc. that I provide as input. Could you share what you have learned so far? Here, or through email?
Regards,
Shahin

21-Topaz II
August 7, 2026

Check out the post above that contains the C++ code in two versions Visual Studio and Embarcadero RAD Studio.  I am not used to Python.

Cheers

Terry

21-Topaz II
August 7, 2026

The actual six files that do the work are included below.  Writing is three files, Reading is three files.  You can try an AI agent to translate the six C++ files to python.

21-Topaz II
August 7, 2026

Hi Shahin,

This is going to save you hours.  Got Chat GPT  with its knowledge to create a python version.  The implementation and example of use.  Untested and exactly as the AI wrote.  You need a sample file *.mcdx file to be used as a template by the writer

21-Topaz II
August 7, 2026

Again Shahin,

Here is the python reader files:

Cheers

Terry