Using quick filter in open file dialog?

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

SolidworksApi macros
Answers 5
DG
DG 2013-08-06 Best Answer

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

SF
SF 2013-08-06

Deepak,

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

Thanks,

David

comment imagecomment image
PM
PM 2013-08-06

David,

  I'm not sure that you have access to those buttons, but you can add the same filters to the open dialog and just change the "Files of type:" drop down to what you are looking for.  That is what those buttons do anyway.

Paul

SF
SF 2013-08-06

Paul,

I understand that and that’s what I have done.  Some of my users asked if the buttons can be added and I did not find anything saying if we have access or not but I think you are right that we don't.

Thanks ,

David

YN
YN 2014-07-31

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