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

Community Tip - Help us improve the PTC Community by taking this short Community Survey! X

Open Run Save and Close Mathcad Prime automatically step by  step

SPRstructur
15-Moonstone

Open Run Save and Close Mathcad Prime automatically step by  step

Dear all

I don't know any code or any Languages only Mathcad Prime.

Please help me my question below. My purpose is to get Platform that can order Mathcad prime sheet Open Run Save and Close automatically step by  step to get Text File without open and run manually that it hard to do with many sheets. And I also attach relevant file as below

Best regards 

SPRstructure

Question.png

 

1 ACCEPTED SOLUTION

Accepted Solutions

Hi,

 

You asked:=

"Can you do every step after open and run, close and save automatically  and then next step do the same and then message appear to "Message: Complete All"? and then click "OK" go to result"

 

To save the files add the three following lines after the lines like "txtStep1.Text = Stage 1 OK" in each of four instances.

 

Delay(0.5)
worksheet.Save()
worksheet.Close(0)

 

Add the delay function at the top

 

Sub Delay( seconds )
    Dim wshShell, strCmd
    Set wshShell = CreateObject( "WScript.Shell" )
    strCmd = wshShell.ExpandEnvironmentStrings( "%COMSPEC% /C (TIMEOUT.EXE /T " & seconds & " /NOBREAK)" )
    wshShell.Run strCmd, 0, 1
    Set wshShell = Nothing
End Sub

 

This has been done in enclosed file.

View solution in original post

14 REPLIES 14

Hi,

"I don't know any code or any Languages only Mathcad Prime."

Start with the example provided in the Prime help.

Example shows how to open and close Mathcad worksheets.

Capture.JPG

Capture2.JPG

Cheers

Terry

Hi,

 

"I don't know any code or any Languages only Mathcad Prime."

A huge learning curve is ahead.  A language needs to be chosen.

 

Either 1, 2, 3, or 4 is possible

 

1:=

An integrated development environment "IDE" is useful to program code in.

It is possible to design a form interface in this IDE

Microsoft releases a community version of its Visual Studio IDE that is free.

Language choice is C++, C#, Visual Basic.

 

https://visualstudio.microsoft.com/downloads/

Community
Powerful IDE, free for students, open-source contributors, and individuals

Free download

 

This covers examples 1 to 4 in Mathcad Help

 

2:=

Visual Basic for Applications "VBA" can be used to both create the form and develop coding in macros associated with Microsoft Office applications like Word, Excel, Access etc

There is no example in Mathcad help but Example 3 and 4 are close.

 

3:=

A free IDE for java coding is called Eclipse

It is available at

https://www.eclipse.org/downloads/packages/

Eclipse IDE for Java Developers

The essential tools for any Java developer, including a Java IDE, a Git client, XML Editor, Maven and Gradle integration

 

This covers example 5 and 9 in Mathcad help

 

4:=

With nothing but a text editor you can enter VBScript and can create a html interface.

 

This covers example 8 in Mathcad help.

 

Good Luck

Cheers

Terry

Capture.JPG

 

 

Hi

Text files should end in an extension.  I have added *.txt to all relevant files.

The problem is distilled into the simplest form with a single visual basic script that sends messages to windows.

Enclosed zip file contains all the relevant files.

Capture.JPG.

Start from Prime file "Input Worksheet", from there you  can ctrl+click on the "Run" link

Capture2.JPG

Capture3.JPG

Watch the messages on screen

 

Cheers

Terry

you are great !
Can you do every step after open and run, close and save automatically  and then next step do the same and then message appear to "Message: Complete All"? and then click "OK" go to result
Best regards 

Hi,

 

Found on the internet a useful and simple way to create the Graphical User Interface for vbscripting.

 

http://veretennikov.org/WSO/

WindowSystemObject (WSO) - provides you with an easy way to create window interfaces using scripting languages such as JScript, VBScript and other.

License: WSO is freeware.

 

I recommend you download and install it.

 

Have added the interface as requested in the posting

Capture4.jpg

Capture5.JPG

To achieve this have simple additions to the vbscript file now called GUI_Interface.vbs

Capture2.JPG

Start as previously in the Prime worksheet "InputWorksheet", change the value of "a" in the matrix and CTRL =Click the Run text

 

Enjoy

Cheers

Terry Hendicott

 

 

Hi,

 

You asked:=

"Can you do every step after open and run, close and save automatically  and then next step do the same and then message appear to "Message: Complete All"? and then click "OK" go to result"

 

To save the files add the three following lines after the lines like "txtStep1.Text = Stage 1 OK" in each of four instances.

 

Delay(0.5)
worksheet.Save()
worksheet.Close(0)

 

Add the delay function at the top

 

Sub Delay( seconds )
    Dim wshShell, strCmd
    Set wshShell = CreateObject( "WScript.Shell" )
    strCmd = wshShell.ExpandEnvironmentStrings( "%COMSPEC% /C (TIMEOUT.EXE /T " & seconds & " /NOBREAK)" )
    wshShell.Run strCmd, 0, 1
    Set wshShell = Nothing
End Sub

 

This has been done in enclosed file.

Hello @terryhendicott 

Sad me, error because my computer or code ?

SPRstructur_0-1643284486250.png

 

It work well after I install WSO
Big Big Thank @terryhendicott for your helping and Sharing.
Good Luck to you

Dear @terryhendicott 
After I increase the index [a b c d] the program not generate the text as shown below
Thank you

SPRstructur_0-1643289495336.png

SPRstructur_1-1643289595640.png

 

 

Hi

Setting the matrix size to 10000 means longer calculation time in each worksheet.

The programming in the loop on each of four worksheets is not time efficient. 

The variable C in the loop needs to resize every time through the loop to cover the matrix getting larger.

Pre-allocation of enough space to start with, alleviates this resizing that happens in the background.  Done this in all four step files.

WRITETEXT and READTEXT are extremely slow process with 10000 x 10000 data points per text file

Capture3.JPG

 

The timing change from 0.043 at size 5 to 67.5 at size 10000 must be allowed for.

My system has a top of the line chip at high speed.

Works when I set the delay to 68 seconds

 

Capture.JPG

Capture2.JPG

 

You need to set the delays accordingly in the VB script, and move the reporting of complete after the saving.

 

The timings work on my machine you may need to adjust.

 

' Open the worksheet:
Set worksheet = mathcad.Open(fileSystemObject.BuildPath(dirScript,"Step3_GA.mcdx"))
worksheet.SetTitle("Step3_GA from VB Script")
worksheet.ResumeCalculation
worksheet.Synchronize
'strMessage = "Step 3 Complete"
'Msg strMessage

Delay(68)
worksheet.Save()
worksheet.Close(0)

txtStep3.Text = "Stage 3 OK"

 

What you need is a couple of edit controls to set the delays

Capture4.jpg

This is an exercise for you.

 

Cheers

Terry

😅😅😅it hard for me for coding Tery

Good Evening  @terryhendicott 
how to write code WSO to delete Text file when we click on Run?

SPRstructur_0-1644748523968.png

 


Best
SPR

Hi,

 

You should not delete Index.txt as it is needed to run from "InputWorksheet"

Have added the lines to remove the Step-#.txt files.

 

' New Lines

Set fs = CreateObject("Scripting.FileSystemObject")

If (fs.FileExists("Step-1.txt"))=true Then
     fs.DeleteFile("Step-1.txt")
End If
If (fs.FileExists("Step-2.txt"))=true Then
    fs.DeleteFile("Step-2.txt")
End If

    If (fs.FileExists("Step-3.txt"))=true Then
fs.DeleteFile("Step-3.txt")
End If

If (fs.FileExists("Step-4.txt"))=true Then
    fs.DeleteFile("Step-4.txt")
End If

set fs = nothing

' New Lines End Above

Thank u Terry

Top Tags