Tushar Suradkar [ www.geocities.com/cadgurucool ]


Create a list of DWG files using Browse for Folder in VB 6

This is 7th in the series of 17 tutorials that show you how to create a menu with bitmaps,
display it in the system tray right click as shown in figure and further
run 15 AutoCAD utilities from the menu.

All the tutorials are available for FREE at :

www.geocities.com/cadgurucool ( Click Tutorials 4U )


All VB6 source code and related ocx files are included with the zip file that contained this tutorial and is also available at the above site.
The entire series of AutoCAD - VB tutorials cover :

  • Create menu with bitmaps using VB 6

  • Put the menu with bitmaps in the system tray using VB 6


  • Drawing to DXF - Convert DWG to DXF without opening AutoCAD

  • Drawing to BMP - Convert DWG to Bitmap format Without Opening AutoCAD

  • Drawing to JEPG - Convert DWG to Joint Pictures Expert Group format - W.O.A.

  • Drawing to GIF - Convert DWG to Graphics Interchange Format - W.O.A.

  • Drawing to TIFF - Convert DWG to Tagged Image File Format - W.O.A.

  • Drawing to CNC - Generate M-G-code from milling profiles in AutoCAD - W. O. A.

  • Drawing to CNC (html) - Generate html file showing the milling profile and CNC program - without opening AutoCAD

  • Attribute Tree List - Display block attributes from a drawing in tree view and list view control just by right clicking on the dwg file in explorer.

  • Attribut to HTML - Generate a html file showing tables of block attributes in a drawing just by right clicking on the dwg file in explorer.

  • Attribut to PDF - Generate a Portable Document Format file showning tables of block attributes in a drawing just by right clickingon the dwg file in explorer.

  • Drawing List - Create a list of all drawings in a folder using the Browse for folder dialog.

  • Slide Library - Create a slide library of all slides ( AutoCAD sld files ) just by right clicking in windows explorer.

  • Slide Library Viewer - Learn to build a small utitlity that displays a list of all slides with preview from a slide library (AutoCAD slb file)


  • All of the above using Visual Basic 6 and without opening AutoCAD .

    Two more that fit in the above series but do not use VB or AutoCAD.

  • Drawing List - Add an item Create DWG List to the right click menu for dwg files in explorer and then quickly create a list of all drawings in the folder.

  • Drawing List - Add an item Create DWG List to the right click menu for all folders in explorer and then quickly create a list of all drawings in the folder.


  • Let us begin

    It is assumed that :

    you have a basic understanding of Visual Basic 6.
    AutoCAD 2000 / 2000i or 2002 is installed.

    Start Visual Basic and open the AcadTray project.
    The acadtray.zip file, this tutorial and the related zip and project files are available (for FREE) at
    www.geocities.com/cadgurucool - Click Tutorials 4U

    Also, another slide.ocx file that has nothing to do with the current tutorial, but is part of the aforesaid series of tutorials, is present in the acadtray.zip file.

    When you open the acadtray.vbp project, an error mesaage will appear regarding the slide.ocx file.

    Ignoring the error message, proceed to VB.

    OR

    You can easily register the slide.ocx file as follows : (first cancel project loading and exit VB)

    1. On the windows taskbar, click Start > Run.
    2. The Run dialog box appears.
    3. Type regsvr32 and then Drag and Drop the slide.ocx file in front of the word regsvr32 that you just typed.
    4. The filename with its fullpath will appear as shown in figure. OK or press Enter.
    6. A message will appear telling you that the registration succeeded.










    Declaring the Variables

    Double click to open dwglist.bas module.
     
      Dim DwgFolder As String
      Dim FileNumber As Integer
      Dim RetVal As Variant
      
      DwgFolder = BrowseFolders("Select folder containing drawing files.")
     
    The Sub is called from one of the menu items.
    The DwgFolder holds the folder to browse.
    FileNumber is for the FreeFile function of VB.
    And Retval for the Shell function.

    Assign DwgFolder, the full path of the folder to browse.
    The BrowseFolders function is defined in the foldbrow.bas module.

    Create a batch file

     
      If DwgFolder = "" Then
          MsgBox "Error : No folder selected"
        Else
        FileNumber = FreeFile
        Open DwgFolder & "\" & "dwglist.bat" For Output As #FileNumber
          Print #FileNumber, "dir *.dwg > dwglist.txt /b" & vbLf
          Print #FileNumber, "exit" & vbLf
        Close #FileNumber
     
    Check if the user cancelled the browse folder dialog.
    Create a batch file called dwglist.bat in the same folder.
    Ask the batch file to redirect the return of the dir command to a text file called dwglist.txt

    Run a batch file

     
        ChDir DwgFolder
        RetVal = Shell(DwgFolder & "\" & "dwglist.bat", vbHide)
        
        If RetVal <> 0 Then
          MsgBox "Drawing List created and will be displayed in notepad"
          RetVal = Shell("notepad.exe " & DwgFolder & "\" & "dwglist.txt", vbNormalFocus)
          Kill DwgFolder & "\" & "dwglist.bat"
        ElseIf RetVal = 0 Then
          MsgBox "Drawing List creation failed !"
        End If
     
    Change the current folder to the selected folder.
    Run the batch file using the Shell function.
    If the shell function succeeded, it returns a non-zero value to RetVal
    Display the dwglist.txt file in notepad, again using the shell function.