Hi there, I have been running up against a consistent issue while trying to replace the referenced file for a drawing with swDM. SwDmDocumentSaveError always returns a zero indicating that it saved happily, but when i check the reference through solidworks open dialog, no change has taken place.
Also i have made absolutely sure that I am using getdocuemnt with the open as read only value set to false. I have additionally tried calling the replace both before, and after using CloseDoc. Either way there are no open errors, no save errors, but no results.
I am aware that this has been touched on in other threads, including this one where i left a very similar comment. Not a lot of traffic there though since it has been marked answered and i decided it would be best to repost this as a new disscussion since the problem obviously has a different solution.
The code I'm using does a lot of other things, so i will just post the relevant (failing) portion here for your picking pleasure.
(and yes, the licKey is present elsewhere in the code, all other swDm methods are working fine)
<p> 'Move drawing files to appropriate folders and re-referenceto new parent files</p><p> For i = LBound(drwFiles) To UBound(drwFiles)</p><p></p><p> If Not drwFiles(i) = Empty Then</p><p> </p><p> Set swDoc = swDm.GetDocument(drwFiles(i), SwDmDocumentType.swDmDocumentPart, False, mOpenErrors)</p><p> Debug.Assert (SwDmDocumentOpenError.swDmDocumentOpenErrorNone = nRetVal)</p><p> swDoc.CloseDoc</p><p> </p><p> '/Set an array of existing references</p><p> DrwRefArr = GetDrawingRefs(drwFiles(i))</p><p> '/Find appropriate b or d folder based on partNo</p><p> destFolder = FindDrwFolder(drwFiles(i))</p><p> </p><p> '/use existing reference array to set new references</p><p> Debug.Print "References Replaced for drawing: " & drwFiles(i)</p><p> For j = LBound(DrwRefArr) To UBound(DrwRefArr)</p><p> oldRef = DrwRefArr(j)</p><p> </p><p> If Not oldRef = Empty Then</p><p> 'Debug.Print oldRef & " Is not empty"</p><p> </p><p> If InStr(oldRef, "BOX") Or InStr(oldRef, "PUSHER") Then</p><p> 'Debug.Print oldRef & " Is not empty but contains box or pusher"</p><p> oldRef = ""</p><p> Else</p><p> newRef = Replace(drwFiles(i), extFind(drwFiles(i)), extFind(oldRef))</p><p> 'newRef = strOutputPath & GetFullPartNo(oldRef) & extFind(oldRef)</p><p> swDoc.ReplaceReference oldRef, newRef</p><p> swDoc.Save</p><p> swDoc.CloseDoc</p><p> Debug.Print " OLD REFERENCE: " & oldRef & " has been replaced with NEW REFERENCE: " & newRef</p><p> Debug.Print ""</p><p> '/Empty ref containers</p><p> oldRef = ""</p><p> newRef = ""</p><p> </p><p> End If</p><p> Else</p><p> End If</p><p> Next j</p><p> </p><p> newName = destFolder & "\\" & GetFullPartNo(drwFiles(i)) & extFind(drwFiles(i))</p><p> newName = UCase(newName)</p><p> </p><p> '/Move Drawing to appropriate b or d folder</p><p> moveError = swDm.MoveDocument(swDoc.FullName, newName, fromChildren, toChildren, vOption, pSrcOption)</p><p> If Not moveError = 0 Then</p><p> Debug.Print "ERROR CODE -" & moveError & "- " & drwFiles(i) & " failed to move to " & FindDrwFolder(newName)</p><p> Debug.Print ""</p><p> Else</p><p> Debug.Print drwFiles(i) & " Has been moved to " & FindDrwFolder(newName)</p><p> Debug.Print ""</p><p> End If</p><p> drwFiles(i) = newName</p><p> </p><p> End If</p><p> </p><p> Set swDoc = Nothing</p><p> destFolder = ""</p><p> refExt = ""</p><p> </p><p> Next i</p><p></p>
