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

Community Tip - Need to share some code when posting a question or reply? Make sure to use the "Insert code sample" menu option. Learn more! X

Automatic Enforced File Save when Referenced Files Modified?

sdudek
1-Newbie

Automatic Enforced File Save when Referenced Files Modified?

I have a MathCad worksheet ("X.xmcd") that references another MathCad sheet ("Y.xmcd"). I am utilizing the ASCII contents of "X.xmcd", the file that lives on the disk. If I modify "Y.xmcd" and open "X.xmcd", I see the changed values of those variables that depend on the contents of "Y.xmcd". However, even if I "save" the file "X.xmcd" by clicking on the save icon (or using Cntrl-S), the date stamp on "X.xmcd" does not change nor does its contents. (That is, there is a discontinuity between what is on disk and what I am seeing on the screen.) I noticed that if I use a "save as" to the same filename it also does nothing. However, if I "save as" to a new file name, the contents in "X.xmcd" have now been updated to reflect what I'm seeing in the GUI.

What is the easiest/fastest/safest method for me to enforce an automatic "save" on file "X.xmcd" that updates the contents on the disk whenever file "Y.xmcd" changes? I would prefer a batch version of any solution.

Thanks,

Scott

3 REPLIES 3
MikeArmstrong
5-Regular Member
(To:sdudek)

You could use a scripted component to save the file for you. Maybe a push button.

Mike

RichardJ
19-Tanzanite
(To:sdudek)

I think there are two underlying problems here:

1) Worksheet X does not know that worksheet Y changed, because it has no record of the previous contents of worksheet Y. It would be possible to write a scripted component that calculates a checksum for worksheet Y, but that still leaves problem 2:

2) Worksheet X knows it has not changed, and so sets an internal flag to say it doesn't need to be saved. This is the NeedsSave property of the worksheet, which you can access via the automation interface. So it appears that when you save it, it looks at the flag, and then does nothing. I actually view this as a bug, and is probably a hangover from the .mcd format. In the .mcd format results of calculations are not saved, so the setting of this flag is correct. In .xmcd format the results of calculations are saved though, so the setting of the flag is incorrect! I don't know how to fix this though. The NeedsSave property cannot be set by the user. Even if it could, doing it from a scripted component will not work because if you have a scripted component in the worksheet the NeedsSave property is always set to true (there's a good reason for this, but I'm not going to get into it).

The last comment in number 2 does lead to one rather cheesy workaround though. Put a component in the worksheet. Any component. It doesn't have to do anything. That will not automatically save worksheet X when worksheet Y changes, but it will mean then when you save worksheet X manually the .xmcd file is updated (I tried this, and it seems to work).

In an attempt to solve this, I've created (with the help of a mathcad technical assistance person) a visual basic script that basically does the following over a set of worksheet files:

Open

Recalculate

Save

Close

Application.Quit

I have a set of MathCad files of the following sizes:

File 1: 3600 K

File 2: 218 K

File 3: 5336 K

File 4: 5026 K

File 5: 3817 K

If I run my VB script for these files, I get the following (approximate) timings:

FileOpen RecalcSave
10:262:280:12
20:498:320:08
30:330:450:13
40:120:250:07
50:060:090:08

So, the entire process to recalculate and save 5 (reasonably small) files is ~15 minutes.

I thought the process might be related to file size, but I that doesn't appear to be the case. The smallest file takes the longest to recalculate. The number and type of calculations in that file (10 arrays of size 10) doesn't appear all that much complicated, though it does reference array values from a referenced file if that matters.

If I open and modify and save interactively, I'm getting slightly faster response but not a whole lot.

One thing that is curious to me: Watching the "process" screen on the task manager, I see that the memory goes up and up during the recalc, to as much as 1GB (finishes around 580MB). Seems like a lot, but I don't know how MathCad uses memory.

Seems like I have a method by which to automate the enforced saving of files - however, in doing so I've discovered that the process is so long that it is cumbersome. Any thoughts on how to streamline the sheets to make the recalcs faster? Or is there an operation I can perform besides a recalc that would have the same effect but which is not as intensive?

Thanks,

Scott

Top Tags