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

MathCad Add-In for Excel: can not save result?

ptc-5804603
1-Newbie

MathCad Add-In for Excel: can not save result?

Hi,all

I create a mathcad object and use variable in0 to receive data from excel. I wirte a assignment statement in the document, ret:=in0. I save the object into a .xmcd file and reopen it using mathcad, ret is always 0 no matter what in0 is before saving. Does it mean that the calculation result can not be saved? Is it possible to save the result through mathcad automation interface?

Thanks

1 ACCEPTED SOLUTION

Accepted Solutions
RichardJ
19-Tanzanite
(To:ptc-5804603)

Posting your question and also sending a PM to someone has the same problem as double posting: you started two discussions that are unconnected, which wastes peoples time. The answer to your question is in this thread, which you found for yourself:

http://communities.ptc.com/message/173796#173796

As I just said in a PM: "As Werner pointed out, what is saved in the XML is not necessarily what appears in the worksheet next time it's loaded. You are looking at an evaluation, not an assignment. The results of the evaluation are saved in the XML so that (in theory) at some time in the distant future when Mathcad no longer exists the results of the calculation are still available in human readable form. However, when you open the Mathcad worksheet, since there is no assignment, there is nothing to evaluate. The only way to do what you want is to modify the XML of an assignment region.".

I just noted that in your sheet you do actually have an assignment ret:=in0. So there is something to evaluate, but since the default value for in0 is 0, that's what you get. You don't need that step, you could just use SetValue to set the value of ret directly, If you do that then when you open the sheet standalone ret will be flagged as an undefined variable. You can take your pick of those two, but what you cannot do is get ret to be 5 by using SetValue.

View solution in original post

15 REPLIES 15
MikeArmstrong
5-Regular Member
(To:ptc-5804603)

What version of Excel and Mathcad are you using?

Could you upload a worksheet?

MathCad 15, Excel 2010.

I uploaded a excel file containing the mathcad object. If you have installed the add-in, I think you can save the object into a .xmcd file and check the result.

MikeArmstrong
5-Regular Member
(To:ptc-5804603)

I have the add-in for Excel 2007, but have never used it. The file opens but I do not know how to save the object into Mathcad.

Are you using Excel 2007? After you installed the add-in, you can go to Excel->options->Add-ins to find it.

MikeArmstrong
5-Regular Member
(To:ptc-5804603)

Yes 2007. I have just done that and realised that the add-in has not been installed on my new machine. However, I can open your Excel sheet and activate the embedded Mathcad component.

I create an example. I save the object into save.xmcd. When I open this file, it shows ret = 0. However, when I open this file with notepad, it shows

<ml:eval>
<ml:id xml:space="preserve">ret</ml:id>
<ml:result>
<ml:real>5</ml:real>
</ml:result>
</ml:eval>

5 is exactly the value I assign to in0 and ret(ret:=in0) through Excel. So I could not understand why it shows ret = 0 when opend by MathCad. Can anyone help with this?

Thanks.

When you save and reopen the Mathcad sheet, the sheet is stand alone and every connection to your Excel sheet is lost. So all ten input variables in0 to in9 default to 0.

When saving a sheet the last calculated results are saved and thats the reason you see the last value of in0 in the xml structure of your saved file when you open it with notepad. But as autocalculation is turned on the sheet is recalculated as soon as you open it at now the "new" values (0) for the input variables tale effect.

Thank you! The saved value for in0 didn't recover when I turn off automatic calculation...It seems there's no way to save the sheet alone?

Correct, you can't avoid the recalc at startup in MC15 and below. This behaviour was changed in Prime.

MikeArmstrong
5-Regular Member
(To:ptc-5804603)

Can you not just use Excel inside Mathcad?

In fact, what I care about is to save the sheet set by third-party application through the Mathcad automation interface. I use the add-in for Excel to test, as I think this add-in is made from the automation interface.

MikeArmstrong
5-Regular Member
(To:ptc-5804603)

So you want to write something to Excel and save that sheet with the written data?

Its not completely clear to me how and what that test will be, But basically spoken - if you want to keep the results of a Mathcad sheet, you would either have to take care that the ituation at startup is the very same as when you left Mathcad (which is normally the case but obviously not in your situation) or you would have to save the calculated data in a file and read it in on next startup (or next compltet recalc).

I also never installed the Excel plugin as I found no use for it, but wouldn't it be more convenient in your case to export the data to this sheet and keep it here? After all as I understand it thats what the plugin is made for.

RichardJ
19-Tanzanite
(To:ptc-5804603)

Posting your question and also sending a PM to someone has the same problem as double posting: you started two discussions that are unconnected, which wastes peoples time. The answer to your question is in this thread, which you found for yourself:

http://communities.ptc.com/message/173796#173796

As I just said in a PM: "As Werner pointed out, what is saved in the XML is not necessarily what appears in the worksheet next time it's loaded. You are looking at an evaluation, not an assignment. The results of the evaluation are saved in the XML so that (in theory) at some time in the distant future when Mathcad no longer exists the results of the calculation are still available in human readable form. However, when you open the Mathcad worksheet, since there is no assignment, there is nothing to evaluate. The only way to do what you want is to modify the XML of an assignment region.".

I just noted that in your sheet you do actually have an assignment ret:=in0. So there is something to evaluate, but since the default value for in0 is 0, that's what you get. You don't need that step, you could just use SetValue to set the value of ret directly, If you do that then when you open the sheet standalone ret will be flagged as an undefined variable. You can take your pick of those two, but what you cannot do is get ret to be 5 by using SetValue.

@Werner @Richard

Thank you very much!

Top Tags