Get Help

Turn on suggestions

Auto-suggest helps you quickly narrow down your search results by suggesting possible matches as you type.

Showing results for

- Community
- :
- PTC Mathcad
- :
- PTC Mathcad
- :
- Re: Getting Outputs with API

Options

- Subscribe to RSS Feed
- Mark Topic as New
- Mark Topic as Read
- Float this Topic for Current User
- Bookmark
- Subscribe
- Mute
- Printer Friendly Page

Auto-suggest helps you quickly narrow down your search results by suggesting possible matches as you type.

Showing results for

07-01-2015
12:28 PM

- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Email to a Friend
- Notify Moderator

07-01-2015
12:28 PM

Getting Outputs with API

Hello everyone.

I made the following function in VBA (Excel) to retrieve the value of the variable B from the mathcad file using the API.

The Variable is defined in the file with a unit i.e. **B := 2 m**

Public Function test2() As Double

Dim objApp As Ptc_MathcadPrime_Automation.Application

Set objApp = New Ptc_MathcadPrime_Automation.Application

Dim b As Ptc_MathcadPrime_Automation.WorksheetReadonlyOptions

Set b = objApp.CreateWorksheetReadonlyOptions

bb = b.SetOptionValue(WorksheetReadonlyOptionNames_RequestToUpdateInputsEnabled, 2)

Dim objCalc As Ptc_MathcadPrime_Automation.IMathcadPrimeWorksheet3

Set objCalc = objApp.OpenEx("C:\Users\kai.jakob\Desktop\Testo.mcdx", b)

Dim a As Ptc_MathcadPrime_Automation.IMathcadPrimeOutputResult

Set a = objCalc.OutputGetRealValue("(@LABEL VARIABLE B)")

Set a = objCalc.OutputGetRealValue("B")

aa = a.RealResult

aaa = a.Units

test2 = aa

objCalc.Close (SaveOption_spSaveChanges)

objApp.Quit (SaveOption_spDiscardChanges)

End Function

The output I get is:

Double: aa = -1.#IND

Unit: aaa = ""

Can anyone tell me what is wrong with those functions?

Solved! Go to Solution.

1 ACCEPTED SOLUTION

Accepted Solutions

10-12-2015
10:32 PM

- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Email to a Friend
- Notify Moderator

10-12-2015
10:32 PM

I was getting the same result (-1.#IND) until I figured out that you must assign your outputs in the Mathcad worksheet.

See the following post I just made: Re: NEW API for Mathcad Prime 3.1 - Page 2 - PTC Community

Good luck.

9 REPLIES 9

09-17-2015
03:04 AM

- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Email to a Friend
- Notify Moderator

09-17-2015
03:04 AM

Ok guys.

I have technically solved the problem: I let Mathcad write a .txt file with the results and units. Excel then reads and deletes the txt.

However I am convinced that there must be an easier solution to this problem.

Has anyone gotten the IMathcadPrimeOutputResult function to work?

09-17-2015
03:10 AM

- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Email to a Friend
- Notify Moderator

09-17-2015
03:10 AM

Are you trying to write variables from Mathcad to Excel?

Mike

09-17-2015
04:23 AM

- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Email to a Friend
- Notify Moderator

09-17-2015
04:23 AM

Yes exactly.

Edit: Well the real goal is to 'remote control' a Mathcad-file from Excel.

At the moment I just start the Mathcad-Calculation from the excel. Then I use Mathcad formulas to import values and units from this same Excel file. The Mathcad outputs are then handled with the txt file I mentioned above.

There must be a simpler solution.

09-17-2015
04:34 AM

- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Email to a Friend
- Notify Moderator

09-17-2015
04:34 AM

Can you use the WRITEEXCEL function?

Mike

09-17-2015
06:54 AM

- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Email to a Friend
- Notify Moderator

09-17-2015
06:54 AM

WRITEEXCEL only writes into closed Excel files. As the Excel should control Mathcad in vba, closing the file is no real option.

(I have to admit that I could have used a .xlsx instead of the .txt for data-transfer. This would probably have been easier.)

09-17-2015
08:49 AM

- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Email to a Friend
- Notify Moderator

09-17-2015
08:49 AM

You could pay $9000 for the documentation NEW API for Mathcad Prime 3.1 - PTC Community

09-18-2015
05:07 AM

- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Email to a Friend
- Notify Moderator

09-18-2015
05:07 AM

I am pondering marking your answer as the right one...

09-18-2015
07:22 AM

- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Email to a Friend
- Notify Moderator

09-18-2015
07:22 AM

I am sure there is a way to get the result without going via a file. I don't have Prime 3.1 though, so I can't even poke around with an object browser to see what is available.

10-12-2015
10:32 PM

- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Email to a Friend
- Notify Moderator

10-12-2015
10:32 PM

I was getting the same result (-1.#IND) until I figured out that you must assign your outputs in the Mathcad worksheet.

See the following post I just made: Re: NEW API for Mathcad Prime 3.1 - Page 2 - PTC Community

Good luck.