Solidworks Macro "Open" Dialog Box

Hi all

I'm looking to open the "Open" dialog box via a macro so that the user can choose which file to open.

Anyone know which command to use?

Thank you

1 Like

Hello, I advise you to use a macro by learning, see here:

 http://help.solidworks.com/2013/French/SolidWorks/sldworks/c_recording_playing_macros.htm

You can also watch my macro save under:

.PL

Thank you for your answer.

I've tried the macro recorder before, but the code is empty if I just open the dialog box and close it. And if I open a file, the code obtained works but it needs a link to a file and I want it to be the user who selects the file to open.

There is no link to your save as macro.

1 Like

Indeed, I just created a tutorial to do this:

http://www.lynkoa.com/tutos/import-export-formats-neutres/macro-solidworks-fen%C3%AAtre-ouvrir

 

1 Like

Thank you for this tutorial!

However, I had found this code on the Solidworks API which opens the dialog box but when I select a file (part or assembly), nothing happens.

The same thing happens with the code you provided.

Do you have any idea why?

1 Like

Do you double click on a part and nothing happens?

Yes, that's right.

The dialog box closes and that's it, the room doesn't open.

Does the code work for you?

I can't test now.

What version and SP of SolidWorks are you in?

And what is the purpose of macro? There may be a way around it.

In fact, the GetOpenFileName function returns the path of the selected file.

To open it, you need to add a line with the OpenDoc6 command with fileName as the path.

I put the code below (the number after fileName in the line "Set Part... " must be 1 if you want to open a part and 2 for an assembly):

 

Dim swApp As Object
Option Explicit

 
Public swModel                  As SldWorks.ModelDoc2

Dim Part As Object
Dim boolstatus As Boolean
Dim longstatus As Long, longwarnings As Long


Sub Main()

 

Dim Filter                      As String

Dim fileName                    As String

Dim fileConfig                  As String

Dim fileDispName                as String

Dim fileOptions                 As Long

 

Set swApp = Application.SldWorks

Filter = "SolidWorks Files (*.sldprt; *.sldasm; *.slddrw)|*.sldprt;*.sldasm;*.slddrw|Filter name (*.fil)|*.fil|All Files (*.*)|*.*|"

fileName = swApp.GetOpenFileName("File to Attach", "", Filter, fileOptions, fileConfig, fileDispName)

Set Part = swApp.OpenDoc6(fileName, 2, 0, "", longstatus, longwarnings)

Debug.Print fileName

 
End Sub

 

Have a nice day

1 Like