How to Recover Coins Using a Macro

Hello, I would like to be able to retrieve a document from a document, to do so I have made my program which works, but I would now like to be able to take another document with another name in the same document. It should be noted that there will always be only one piece in this document. Is it possible to have a macro that takes all the pieces of the same document?

For example:  boolstatus = swApp.LoadFile2("C:\Users\Desktop\new folder\ (all or filename)", "")

Hello

Can you share your current macro?

No worries:


macro_ouverture_dossier.swp

Can you explain what you want to do? I thought the macro would make me understand what you mean by "get one coin" and "take all the coins", but it's not.

Also the macro uses "SelectByRay" which is a bit random

If you try to select edges, it is better to do it with GetBodies2  then GetFirstFace / GetNextFace then GetEdges

 

Thank you very much for the answer. I'm a newcomer in this field so I'm missing some notions so thank you very much :). 

In fact, I would like the software to make a tooling automatically in relation to a part in a file, let's imagine that I have a part A and a part B. If I create my macro with part A as a base, it works but now if I remove part A from the folder and replace it with B, then it doesn't work anymore since they don't have the same name. Is there a way to overcome this problem?

You can select the file with a dialog box:

' cliquer dans le menu de la fenêtre VBA: Tools > References > sélectionner: "microsoft Excel xx.0 object library"
Sub main()
    Dim xlsObject As Excel.Application
    Dim fdFolder As Office.FileDialog

    Set xlsObject = New Excel.Application
    xlsObject.Visible = False
    Set fdFolder = xlsObject.Application.FileDialog(msoFileDialogFilePicker)
       fdFolder.Filters.Clear
    fdFolder.Filters.Add "SolidWorks Files", "*.sld*"
    fdFolder.Show
    Debug.Print "fichier sélectionné: " & fdFolder.SelectedItems(1)
    xlsObject.Quit
    Set xlsObject = Nothing
End Sub

or browse all the files in a folder with:

Sub main()
Dim oFSO As Object
Dim oFolder As Object
Dim oFile As Object
Set oFSO = CreateObject("Scripting.FileSystemObject")
Set oFolder = oFSO.GetFolder("C:\Users\...")
For Each oFile In oFolder.Files
    Debug.Print oFile.Name
Next oFile
End Sub

 

Hello

If, as mentioned above, you still have only one file in the folder in question, you can retrieve its name with the DIR function:

    Dim Dossier As String
    Dossier = "C:\Temp\divers\" 'Ligne à modifier pour mettre le nom de ton dossier
    Dim Fichier As String
    Fichier = Dir(Dossier)
    Debug.Print Dossier & Fichier
    boolstatus = swApp.LoadFile2(Dossier & Fichier, "")

 

Kind regards

Thank you very much for your answers, I'll test it. 

Be careful however with the type of file you want to open, you use the LoadFile2 function (take LoadFile4 to be up to date) which is for non-native Solidworks files, if it's for a native Solidworks file you have to use the OpenDoc6 function and therefore do a check on the file type (asm, PRT or DRW).

Kind regards

1 Like

It works, thank you.

OK, all you have to do is validate the answer that solved your question...

Kind regards