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)
'Move drawing files to appropriate folders and re-referenceto new parent files
For i = LBound(drwFiles) To UBound(drwFiles)
If Not drwFiles(i) = Empty Then
Set swDoc = swDm.GetDocument(drwFiles(i), SwDmDocumentType.swDmDocumentPart, False, mOpenErrors)
Debug.Assert (SwDmDocumentOpenError.swDmDocumentOpenErrorNone = nRetVal)
'/Set an array of existing references
DrwRefArr = GetDrawingRefs(drwFiles(i))
'/Find appropriate b or d folder based on partNo
destFolder = FindDrwFolder(drwFiles(i))
'/use existing reference array to set new references
Debug.Print "References Replaced for drawing: " & drwFiles(i)
For j = LBound(DrwRefArr) To UBound(DrwRefArr)
oldRef = DrwRefArr(j)
If Not oldRef = Empty Then
'Debug.Print oldRef & " Is not empty"
If InStr(oldRef, "BOX") Or InStr(oldRef, "PUSHER") Then
'Debug.Print oldRef & " Is not empty but contains box or pusher"
oldRef = ""
newRef = Replace(drwFiles(i), extFind(drwFiles(i)), extFind(oldRef))
'newRef = strOutputPath & GetFullPartNo(oldRef) & extFind(oldRef)
swDoc.ReplaceReference oldRef, newRef
Debug.Print " OLD REFERENCE: " & oldRef & " has been replaced with NEW REFERENCE: " & newRef
'/Empty ref containers
oldRef = ""
newRef = ""
newName = destFolder & "\" & GetFullPartNo(drwFiles(i)) & extFind(drwFiles(i))
newName = UCase(newName)
'/Move Drawing to appropriate b or d folder
moveError = swDm.MoveDocument(swDoc.FullName, newName, fromChildren, toChildren, vOption, pSrcOption)
If Not moveError = 0 Then
Debug.Print "ERROR CODE -" & moveError & "- " & drwFiles(i) & " failed to move to " & FindDrwFolder(newName)
Debug.Print drwFiles(i) & " Has been moved to " & FindDrwFolder(newName)
drwFiles(i) = newName
Set swDoc = Nothing
destFolder = ""
refExt = ""