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

Community Tip - Have a PTC product question you need answered fast? Chances are someone has asked it before. Learn about the community search. X

Exporting Mathcad 15 values to CSV/text file file using VBS

TD_11399801
3-Newcomer

Exporting Mathcad 15 values to CSV/text file file using VBS

Hello, 

 

I was wondering if I could get help with a VBS script to export bolded text with an equal sign from a Mathcad file to a cvs/txt file 

 

An example of text to export is 

TD_11399801_0-1729690051919.png

Val1 = 1 and Val2 =2  would print to the cvs/txt file as

                Val1,”1”

                Val2,”2”

While the remaining text would be ignored. 

 

Attached is a vbs script that gets all of the text from a Mathcad, but I need to add a conditional that will only print text if it is Bolded and has an equals (=) sign.

I cannot work on this at work since running scripts is blocked and I am working on permission to run this one. 

6 REPLIES 6

Hi @TD_11399801,

Thank you for your question!

Your post appears well documented but has not yet received any response. I am replying to raise awareness. Hopefully, another community member will be able to help.

Also, feel free to add any additional information you think might be relevant.

 

Best regards,

Catalina
PTC Community Moderator

Hi,

Sorry it has taken so long to respond.

 

Every region in the worksheet has a property called "Tag".  You can set this for individual regions to the same value. 

It is possible in vbscript to read the Tag property to see  which ones are tagged and respond accordingly.

Right click  on a region in Mathcad 15 and select Properties.

You get this dialog box to set the Tag.

Capture2.JPG

 

' MathcadExtractText.vbs
Set Mathcad = CreateObject("Mathcad.Application")
Set Worksheet = Mathcad.Worksheets.Open("F:\Prime\VB\worksheet.xmcd")

Set TextFile = CreateObject("Scripting.FileSystemObject").CreateTextFile("F:\Prime\VB\output.txt", True)

For Each Region In Worksheet.Regions
    If Region.Type = 1 Then ' denotes an expression region in Mathcad
        bstr = Region.Tag' Region.XML does not work either.
        
        tokens = Split(bstr, vbCrLf)
        For i = 0 To UBound(tokens)
    		 TextFile.WriteLine(tokens(i))
		Next
        
        
    End If
Next

TextFile.Close
Worksheet.Close
Mathcad.Quit

 

 

 

ThisOne
ThisOne

 

Hello @terryhendicott

 

Thank you for your response! Your solution accomplishes most of what I was looking to achieve. However, it relies on manually setting each text region with a Tag, which is still an error prone process.

 

Do you know if VBS can be used to check if a text region is bold and if there is an equals '=' sign? These are the two conditionals that separate the output text from the rest. 

Can VBS further determine text before and after the equals sign, and print them separately? 

For example Val1 = 1, would print as Val1,1

 

I am hoping to build on the attached "automatic.docx" script which grabs all the text and add conditionals to only print text that is bold and has an equal sign, ie TD_11399801_0-1730467903279.png

 

Thank you!

Hi,

The help pages in Developers Reference show that a property called XML can be called to show the XML of a region in Mathcad 15.

I could not get this to work,

The XML of a region should include the text of the variable name and the value of the variable.  This XML could then be text processed to get the value you need.

 

Cheers

Terry

I appreciate the effort Terry but I am not familiar with XML and this is not a viable path to pursue. 

StuartBruff
23-Emerald III
(To:TD_11399801)

I haven't used Mathcad 15 for a long time and don't have it installed on any of my PCs, however ...

 

I vaguely recall that a Math Style forms part of a variable's/function's name, you should be able to interrogate a Math Region to obtain the Math Style for the style forms part of the identity of the name.  You should also be able to obtain the variable's value.  So, if the VBScript can get the Math Style then you could create a Math Style that makes the variable name bold, change Val1 and Val2 to be Math Regions, apply the style to Val1=1 and Val2=1 when needed, then get the VBScript to check for this Math Style.

 

An alternative method might be to use a Checkbox next to each variable.  Instead of making Val1 and Val2 bold, you'd tick the associated checkbox to indicate you'd like the text exported. You could read the checkboxes in VBScript. If you changed Val1 and Val2 to variables you might even be able to use one of the WRITE functions to create the file you want by looking at the values of the checkboxes..

 

Stuart

Announcements

Top Tags