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 : 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. |
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. 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 #FileNumberCheck 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 IfChange 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. |