Notifications
Clear all

[Closed] Deleting PC2 file in mxs locks file?

Hey all!
I’m attempting to create a script that automatically goes through a scene and applies a Point cache 2 modifier for objects that have certain properties, then save out the .pc2 files.

I’m encountering a problem where I’m unable to delete existing .pc2 files. When I use a command for example

deleteFile “c:\ eapot.pc2”, mxs returns true, but when you check it via windows explorer, the file is still there. Refreshing it does not help, and dragging it to the recycle bin doesn’t help either (windows explorer gives an access is denied error).

The only way thus far is to either close max, or do a resetMAXFile(). Is there a way to get around this or is the resetMaxFile() my best bet?

Thanks!

6 Replies
1 Reply
(@mustan9)
Joined: 11 months ago

Posts: 0

We’ve had problems with the PC modifier not releasing file locks on files as well.

When the modifier is deleted. A instance remains in memory for the undo stack, and maybe other things. Try clearing the undo and see if that helps. Another option is before you delete the PC is to set it to another file like “temp.pc2”, and see if it releases the old file.

Ive had the same thing with text files ,I found that I had to close the file in the script to release it.

in_file = openFile ((GetDir #import)+ na ) this line opens my file

work on file na … and so on …



close in_file < this line will release the file …

hope this was some help…

Are the PC2 files still referenced by a PointCache modifier? Or do you delete the PointCache modifier first, and the file is still locked after that (that would be a problem in PointCache itself if it were the case).

If a file is locked by MAXScript itself (for example when reading/writing using fileStream methods but not closing the file), a manual garbage collection usually releases it – gc().
But I don’t think this has anything to do with your PointCache problem…

Dmaxer, Bobo and Matthew, thanks for the tips! I will try them out, and post my results in this thread. I didn’t consider using gc() or the undo stack. Thanks!!

Regards,
Alvin

1 Reply
(@bobo)
Joined: 11 months ago

Posts: 0

Calling gc() has the side effect of killing the Undo buffer

Hey everyone! Sorry for the late reply, was occupied by another project, only managed to get back to this script today

I got it working finally using the method mustan9 describes. By just replacing the .cacheFile with parameter a temp pc2 string, the deleteFile method works perfectly, no need to restart max.

Thanks all for the help. Learnt a few new tricks for the gc and undobuffer

Regards,
Alvin