1 Reply Latest reply on Dec 30, 2015 8:41 PM by Nicolas Ziegler

    ModelDoc2::ForceReleaseLocks Doesn't Properly Manage Tilde Files

    Jim Sculley

      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:

       

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

       

      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.