SOLIDWORKS Document Manager Issues

I’m trying to use SWDM GetComponents methods to list all the components of an assembly file. The method works OK but results is not. The outcome path is listed as different drives from where several components were taken to add to the assembly. But now all the components are in the same folder yet SWDM still points them to the old location. I’ve even tried with opening and saving the file before running SWDM macro but it still behaves the same. So asking other API experts as what could be the issue and if there is any solution to fix it.

I’m using codes from this macro (Get all assembly components using SOLIDWORKS Document Manager API) by @artem

Thanks in advance.

P.S. I can not share the files.

Open, rebuild (all), and save?

This too not worked. Even after pack and go, SWDM refers to old locations.

Is it an old solidworks assembly?

1 Like

It could be but have been saved to 2022 version recently.

I can confirm that I see the same thing until I open the assembly and save it again. After saving, the paths reflect the current location of all referenced files.

With your assembly, can you confirm whether the [File → Find References] dialog agrees with what you are seeing with the DM output?

1 Like

The File references are correct when checked in the Find References dialog but DM output is not. Even same issue after opening and saving the file.

Does this code show the same invalid paths for your files?

Prior to saving my assembly, when GetComponents() produces invalid paths, the GetExternalReferences function shows the correct path.

SwDMSearchOption dmSearchOpt;

dmSearchOpt = dmApp.GetSearchOptionObject();

var refs = dmDoc.GetAllExternalReferences5(dmSearchOpt, out object brokenRefVar, out object IsVirtual, out object TimeStamp, out object ImportedPaths);

string[] paths = refs as string[];
foreach(var path in paths )

Edit: I just realized this is intended for use on drawings only, although it works on my assembly as well.
This code may help show what’s changed

dmDoc.GetChangedReferences(out object originalreferences, out object newreferences);
string[] orefs = originalreferences as string[];
string[] nrefs = newreferences as string[];
for (int f = 0; f < orefs.Length; f++)
    Console.WriteLine($"Old: {orefs[f] + Environment.NewLine}New: {nrefs[f] + Environment.NewLine}");
1 Like

Thanks Alex, I’ll try this out.

Hi Alex, the codes seems to work (on small files with few components) but still fails on some files (big ones with 1k plus components) which is weird. So I’ve lost the hopes on using SWDM for this particular case :frowning:

Thank you for the help.

1 Like

this is known behaviour to support PDM systems and data migration. When working in SolidWorks (without PDM) reference document paths are stored in document. When a document is saved or migrated to PDM the references are managed in PDM database. SolidWorks stores TWO old locations of the referenced documents. You will have to use some file scripting functions to validated if the path or file exist in the old locations.