In my company we reuse parts/weldments/assemblies quite a bit, usually with a few small changes. Not enough to really justify a new drawing. So Ive implemented a series of Renaming functions which will save a new copy of the file, new drawing etc. Ive done this before, and copied the drawing by doing an open and saveAs on the drawing first, then leaving it open to rename the actual component. However on larger assemblies & weldments this is incredibly slow. I am trying to use a System.IO File copy on the drawing, and then replace the references, but its not working.
The code below inside the Try block, for when the new location is in our Vault, works great. When saving to a location outside of our vault (such as to my desktop), the ReplaceReferencedDocument fails, consistently. Ive tried letting it wait (Thus the Thread.Sleep) to no effect. Both files exist on my desktop, but no matter how long I wait for it fails. Ive fought with this on and off for quite awhile to no avail. Does anyone have any input on this? is there a function other than File.Copy I should be using?
SolidworksApi/macrossMod.Extension.SaveAs(newName, 0, 1 + saveType, null, ref lErrors, ref lWarnings);
if (dwgName != "")
{
try
{
setVault();fol = (IEdmFolder10)vault.GetFolderFromPath(Path.GetDirectoryName(newDWG));
fol.AddFile2(this.Handle.ToInt32(), dwgName, out lErrors, newDWG, 1);
}
catch(Exception e)
{
File.Copy(dwgName, newDWG);
}
sApp.CloseDoc(newDWG);
System.Threading.Thread.Sleep(5000);
sApp.ReplaceReferencedDocument(newDWG, oldname, newName);
}