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 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?
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 )
{
Console.WriteLine(path);
}
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}");
}
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
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.