[VB.net] Solidworks Reference Extraction

Hello

 

Is there a way to extract the references from a file from vb.net?

I looked in the Solidworks visual basic API but found nothing concrete :/

 

Kind regards

Hello, a priori it's possible. You need to declare SolidWorks and add the corresponding library, see this link:

http://help.solidworks.com/2014/english/api/sldworksapiprogguide%5Cgettingstarted%5Cvisual_basic_.net_standalone_and_add-in_applications.htm

See this comm thread

http://www.lynkoa.com/forum/autres/vba-excel-pour-solidworks

@+ ;-)

Hello .PL & gt22

Indeed the declaration is mandatory which I have already done because currently I already change references with my software the problem is that I have to fill them in one by one in a table that's why I try to extract the references directly :)

What exactly does it mean to extract references?
1 Like

I would like to be able to retrieve from an ASM or DRW type file the references they have

Example:

The "drawing 1.SLDDRW" file refers to the assembly "assembly1. SLDASM"

The "assembly1. SLDASM" Refers to the part "Piece1.SLDPRT"

I would like to retrieve the values "assembly1. SLDASM" and "Piece1.SLDPRT" in automatic

I don't know if I'm understandable :/

1 Like
OK, I think that from the moment SolidWorks is declared, it's the same as in VBA? In fact, since a drawing, you have to retrieve the first view to retrieve the associated 3D.

You have to use getfirstview to retrieve the basemap, then getnextview to retrieve the first view, and finally referenceddocument to have access to the corresponding 3D file.

I think there's an example in this macro I posted on Lynkoa:

http://www.lynkoa.com/tutos/3d/macro-enregistrer-sous-avec-solidworks

Thank you for your answer.PL

I just looked at your code and it seems to me Complex for what I want to do, by that I mean that from solidworks by clicking on a drawing more on reference you get the window as an attachment and it would suit me greatly because it contains the folder and the name of the part


ref.png
1 Like

Hello

You are actually looking to get the same results as by doing File/Search for references and then the "Copy list" button. That's right?

Then all you have to do is paste it into an Excel file.

2 Likes

Hello Benoit.LF,

Indeed this is what I want to get the info directly after I would not go through excel but directly stored in vb.net but that's it! :)

It's not that complicated and it's the only method I know of! A little reminder, there can be several different documents on a drawing, so several references...

The macro I posted does something else of course, but it's the beginning of the code that's interesting for this application.

See this link which gives the same solution:

http://help.solidworks.com/2012/English/api/sldworksapi/Get_Document_Referenced_by_Drawing_View_Example_VB.htm

After I am interested in a solution that does this in less than 3 lines of code!! (Without the declarations of course!)
Otherwise for an assembly, GetComponent should be used:

http://help.solidworks.com/2012/English/api/sldworksapi/SolidWorks.Interop.sldworks~SolidWorks.Interop.sldworks.IAssemblyDoc~GetComponents.html

A solution for external references (is it all references?) in about 50 lines:

http://help.solidworks.com/2013/English/api/swdocmgrapi/Get_All_External_References_for_Drawing_Example_VBNET.htm

I found a Provisional solution that may take a long time, I change ALL the references, even the one that doesn't exist, SOlidWorks doesn't flinch.

 

Hello

The API to use is  : GetDocumentDependencies2

http://help.solidworks.com/2013/english/api/sldworksapi/solidworks.interop.sldworks~solidworks.interop.sldworks.isldworks~getdocumentdependencies2.html

it returns all external references of the file 

Philippe

1 Like