ListExternalFileReferences and ReplaceReferencedDocument without Opening

Programming and macros
User avatar
mihkov
Posts: 33
Joined: Sun Feb 05, 2023 2:01 am
Answers: 0
x 14
x 20

ListExternalFileReferences and ReplaceReferencedDocument without Opening

Unread post by mihkov »

Can I get external links of a part without opening it, as the Solidworks application does with: File-Open-Links.
I want to replace a substring in the file name of a part that is referenced by the part being opened using the "swApp.ReplaceReferencedDocument" function.
It allows you to change links only for files that are NOT open.
I only know the function: swModDocExt.ListExternalFileReferences
which allows you to get external links from an already open document:
Set swModel As SldWorks.ModelDoc2
Set swModDocExt = swModel.Extension

I saw this https://help.solidworks.com/2021/englis ... ple_VB.htm, but here we already know in advance: sOldDoc and sNewDoc. And I want to find out: sOldDoc and if it contains the substring “MD22” then replace it with “MD33”. And it turns out that I need to load the file to find out if there are suitable external links in it, if so, modify them, then unload the file, then, as in the example, replace the external links and open the part file with already replaced external links.
I would like to do this: Knowing the path to the file, get an array of links to whom it refers to, if there is what I need there, replace the links and open the file.
I suspect that you will have to use FileOpenPreNotifyEventHandler to track the attempt to open the file, get the path to the file, and then you need to get external links without opening it.
Снимок экрана 2023-11-04 173226.png
JeromeP
Posts: 12
Joined: Wed Mar 24, 2021 12:40 pm
Answers: 0
x 1
x 2

Re: ListExternalFileReferences and ReplaceReferencedDocument without Opening

Unread post by JeromeP »

To get the list of external references and replace references without opening any file, you can use document manager's functions
GetAllExternalReferences4: https://help.solidworks.com/2012/englis ... nces4.html
and ReplaceReference: https://help.solidworks.com/2018/englis ... rence.html

See here for an example
https://www.codestack.net/solidworks-do ... eferences/
Post Reply