There is this method IComponent2.GetPathName() which gives the path of the component file.
It works well for unsuppressed components. But I have trouble using it (successfully) for suppressed components, because it will only return the path that was saved in the document, not the ACTUAL path:
Assume I have an assembly A with path C:\Users\me\example\A.SLDASM which has a component B with path C:\Users\me\example\B.SLDPRT. I suppress B inside A. Then I give the folder "example" to a colleague who puts it to the following location: D:\foo\. So he has A with ACTUAL path D:\foo\example\A.SLDASM and B with ACTUAL path D:\foo\example\B.SLDPRT. But if he opens A in SolidWorks and calls IComponent2.GetPathName() on component B, he will still get C:\Users\me\example\B.SLDPRT. But I need him to get D:\foo\example\B.SLDPRT instead. How do I do this via API?
The API help for IComponent2.GetPathName() states
This method does not apply search criteria or look in the current working directory for the component file reference if the component is lightweight or suppressed.
So how do I apply this Swx search via API?
Jana,
If the path is always common (i.e. a shared network location or similar) or in the same location as the parent assembly, then you could use a dir() search. If it is unknown, you may have to add a userform where the user could input where to search.
I use a search that looks through 3-12 common locations depending on the macro. I am not telling SolidWorks to replace the destination though. There may be a method for that, but I'm not familiar with it. If you only want it to search in a single folder, you can remove the outside loop and an input the IComponent2.GetPathName() result into strPath or just put one path in dest and you could always expand later if needed.