Skip to main content
6-Contributor
March 3, 2026
Solved

Mathcad Prime Python Scripts - New Line in text files causes a crash

  • March 3, 2026
  • 2 replies
  • 168 views

Hello,

 

I use Python to extract data from Mathcad Prime files, based on the previous post below.

 

One thing I noticed is that our Python tool will crash when you have a new line in a text region. Getting rid of the new line in the text region gets rid of the crashing issue.

 

When I go into the Mathcad .zip file with all of the XML data, I do not see any difference between two files - one with text with a new line and one  with no new line.

 

Where would I find the new line data in the text region? I will update the Python code to catch new lines, but I dont even see where the new lines are in the text region.

 

TC_10696099_0-1772546868639.png

 

TC_10696099_1-1772546874776.png

 

 

Mathcad Prime 9.0 Scripting with XML Data - PTC Community

Best answer by Werner_E

When you unzip a mcdx file you should see a directory \mathcad\xaml

In this directory you will find some files named FlowDocument0.XamlPackage,  FlowDocument1.XamlPackage, etc.

Each text region has its own file here. 

The numbers these FlowDoucument#.XamlPackage file seem to correspond with the region-id given in worksheet.xml, but to be on the safe side you should look at _rels\worksheet.xml.rels where you can see which FlowDoucument#.XamlPackage corresponds to which irem-idref given in worksheet.xml.

These FlowDoucument#.XamlPackage files are once again renamed zip-files! If you unzip them you should see a directory Xaml and inside  a file Document.xaml. This file contains among others the actual text of the text region.

Each line of text is enclosed within <Run style ....> ... </Run> tags and for an empty line the closing </Run> immediately follows the opening < Run ....> without any text in-between.

 

2 replies

6-Contributor
March 3, 2026

I also did a BeyondCompare of two Mathcad Prime XML files. The file on the left has a new line in the text region and the file on the right does not have a new line in the text region.

 

The actual height is larger for the file on the left since it has the new line, but otherwise everything else is the same.

 

I see the text item-idref is different between the two files. What is that used for? Is that where text data in the actual Mathcad Prime files is stored?

 

I am not a software person so excuse my ignorance, 

 

 

Werner_E25-Diamond IAnswer
25-Diamond I
March 3, 2026

When you unzip a mcdx file you should see a directory \mathcad\xaml

In this directory you will find some files named FlowDocument0.XamlPackage,  FlowDocument1.XamlPackage, etc.

Each text region has its own file here. 

The numbers these FlowDoucument#.XamlPackage file seem to correspond with the region-id given in worksheet.xml, but to be on the safe side you should look at _rels\worksheet.xml.rels where you can see which FlowDoucument#.XamlPackage corresponds to which irem-idref given in worksheet.xml.

These FlowDoucument#.XamlPackage files are once again renamed zip-files! If you unzip them you should see a directory Xaml and inside  a file Document.xaml. This file contains among others the actual text of the text region.

Each line of text is enclosed within <Run style ....> ... </Run> tags and for an empty line the closing </Run> immediately follows the opening < Run ....> without any text in-between.