All of our SolidWorks files are saved inside a 'master' folder on the
network. Within that folder are client subfolders. Within the client
subfolders are project subfolders, with all SW files
(parts/assemblies/drawings) for a project residing in the project subfolder.
Occasionally we'll reference files across project folders.
I'd like to rename the master folder. For the bulk of our files, this will
not harm a thing, as the references will fix themselves (since they're
contained within a subfolder). But, references between project folders will
be broken and will need manually fixed.
Is there a way to traverse through a set of file references and change every
instance of a folder name to the new folder name (thus fixing all
references)? I imagine it as a sort of 'find and replace' function in the
references. Otherwise, we'll have to fix these as we find them. These
cross-folder references only exist in a small percentage of our files, but
I'd rather fix them myself than rely on the drafting group to fix them as
they find them.
Can it be done, in SW or SW Explorer or some custom program? Let me know if
so. Thanks,
Brian
In TOOLS/OPTIONS/FILE NAMES/REFERENCES point to the root of the new
(identical) tree of folders.
Then in TOOLS/OPTIONS/EXTERNAL REFERENCES turn on Search External
References. Also check open referenced files read only and don't promt
to save read only files.
What SW will then do is be forced to recursively look up references in
the folder tree named in REFERENCES. We do this all the time by having
two identical folder trees, one a vault and the other for working
files.
You can look up the External Reference search procedure in SW Help. It
is presented in a very complex way, but it seems to work.
For a similar situation file post-fixes didn't get updated and I used
this code to modify the names of the file references to reflect the
post-fix. Anyway with a little modification it could suit your needs.
Dim swApp As SldWorks.SldWorks
Dim fs As New FileSystemObject
Dim Folder As Scripting.Folder
Dim File As Scripting.File
Sub main()
Set swApp = Application.SldWorks
Set Folder = fs.GetFolder("PathTOFolderGettingUpdated")
Dim c As Long
c = 1
For c = 1 To Folder.Files.Count
File = Folder.Files.Item(c)
If InStr(1, VBA.UCase(fs.GetExtensionName(File.Path)),
UCase("sld"), vbTextCompare) > 0 Then
ModifyRefs (File.Path)
End If
Next
End Sub
Public Sub ModifyRefs(ByVal Path As String)
Dim Refs As Variant
Dim i As Variant
Dim c As Long
Dim OrigVal As String
Refs = swApp.GetDocumentDependencies2(Path, False, True, False)
c = 1
If IsArray(Refs) Then
For c = 1 To UBound(Refs) Step 2
i = Refs(c)
OrigVal = i
i = Replace(i, "\\", "\", Compare:=vbTextCompare)
If InStr(1, i, " onsite.", vbTextCompare) = 0 Then
i = Replace(i, ".sld", " onsite.sld",
Compare:=vbTextCompare)
End If
If i <> OrigVal Then
swApp.ReplaceReferencedDocument Path, OrigVal, i
End If
Next
End If
End Sub