ModelDoc2::ForceReleaseLocks Doesn't Properly Manage Tilde Files

While trying to resolve a much uglier and more complicated problem, I have discovered that ModelDoc2::ForceReleaseLocks​ and its companion method ModelDoc2::ReloadOrReplace​ do not properly manage the temporary lock (tilde) files associated with the model.  Consider the following simple C# macro:

<p>public void Main()</p><p>        {</p><p>            ModelDoc2 mDoc = (ModelDoc2)swApp.ActiveDoc;</p><p>            int retval = mDoc.ForceReleaseLocks();</p><p>            if (retval == 1)</p><p>            {</p><p>                string dirName = Path.GetDirectoryName(mDoc.GetPathName());</p><p>                string fileName = Path.GetFileName(mDoc.GetPathName());</p><p>                string newFileName = dirName + Path.DirectorySeparatorChar + "A" + fileName;</p><p>                File.Move(mDoc.GetPathName(), newFileName);</p><p>                retval = mDoc.ReloadOrReplace(false, newFileName, true);</p><p>            }</p><p>        }</p>

This code simply releases the locks on an open part file, renames the file by prepending it with 'A' and then reloads the new model.  What I have found is that the tilde file for the original part file is never deleted.  For instance, if I open a file named A.sldprt, a tilde file is created named ~\\\$A.sldprt.  After the macro is run, there are now two tilde files: ~\\\$A.sldprt and ~\\\$AA.sldprt.  This rogue tilde file will persist even after closing all documents and even after closing SW itself.  With a name like ForceReleaseLocks, you would think that deleting the lock file would be one of its primary functions.

SolidworksApi macros
Comments 1
NZ
NZ 2015-12-31

I do have the exact same problem. I tried different things to get rid of it, but the handle on the original file is gone after I use ReloadOrReplace so I cannot do anything on that tilde file either with EPDM API OR SolidWorks API.

Have you found a workaround?