5 Replies Latest reply on Jul 31, 2014 5:01 AM by Yong Ning

    Using quick filter in open file dialog?

    David Watkins

      Is there a way to add the quick filter for parts, assemblies and drawings to the open file dialog? I am using the GetOpenFileName call and can add the filters in there for them but it would be better if I can have the quick filter also. Is this available?

       

      Thanks,

      David

        • Re: Using quick filter in open file dialog?
          Deepak Gupta

          Check the Open File Example (VBA)  in the SW API Help files.

            • Re: Using quick filter in open file dialog?
              David Watkins

              Deepak,

              I am looking for the quick filter buttons that were added in SW 2013 .

              QF.JPG

              Thanks,

              David

              • Re: Using quick filter in open file dialog?
                Yong Ning

                thanks your link web.

                follow code, can be open file from folder

                 

                 

                'how to prompt the user for the name of the file to open. This example also shows how to set up filters by file types.

                 

                '---------------------------------------------------------

                '

                ' Preconditions: Open the Immediate window.

                '

                ' Postconditions:

                ' 1. The File to Attach dialog is displayed and the file

                '    types specified in the filter are listed.

                ' 2. Examine the Immediate window to verify that the

                '    name of the file you selected matches what the name

                '    of the printed to the Immediate window.

                '

                 

                *********************************

                Private Sub OpenDocument()

                   'SolidWorks Forums: Using quick filter in open file dialog?

                   ''https://forum.solidworks.com/message/442407#442407

                 

                  Dim T: T = Timer

                  Dim Path, FileName, Filter

                  Dim fileConfig As String, fileDispName As String, fileOptions As Long

                    Dim SwApp As SldWorks.SldWorks, SwDraw As DrawingDoc

                    Set SwApp = GetObject(, "SldWorks.Application")

                    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 SwDraw = SwOpenFile(SwApp, FileName)

                    Debug.Print SwDraw.GetPathName

                  Timing T

                End Sub

                 

                 

                 

                 

                Function Timing(T)

                    Dim ss, h, m

                    ss = Timer - T

                    h = Int(ss / 3600)

                    m = Int((ss Mod 3600) / 60)

                    ss = Int(ss Mod 60)

                    Debug.Print h & "时:" & m & "分:" & ss & "秒"

                    MsgBox h & "时:" & m & "分:" & ss & "秒"

                 

                 

                End Function

                ''返回装配体中所有零件和子装配体的实体名。

                Function SwOpenFile(SwApp, OpenFile)

                    'Debug.Print OpenFile

                '    SwApp.Visible = True

                    Dim SwModel             As Object

                    Dim nDocType            As Long

                    Dim nErrors             As Long

                    Dim nWarnings           As Long

                    Dim swOpenDocOptions_Silent

                    swOpenDocOptions_Silent = 1

                    ' Determine type of SolidWorks file based on file extension

                 

                 

                    If InStr(LCase(OpenFile), "sldprt") > 0 Then

                        nDocType = 1 'swDocPART

                    ElseIf InStr(LCase(OpenFile), "sldasm") > 0 Then

                        nDocType = 2 'swDocASSEMBLY

                    ElseIf InStr(LCase(OpenFile), "slddrw") > 0 Then

                        nDocType = 3 'swDocDRAWING

                    Else

                        ' Probably not a SolidWorks file...

                        nDocType = swDocNONE

                        '...so the file cannot be opened

                        Exit Function

                    End If

                    ''

                    Set SwModel = SwApp.OpenDoc6(OpenFile, nDocType, _

                                    swOpenDocOptions_Silent, "", nErrors, nWarnings)

                    'SwApp.Visible = True

                    Set SwOpenFile = SwModel

                    'Debug.Print SwModel.GetPathName

                End Function