
|
This is 9th 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 SlideLibrary.bas module.
Option Explicit
Public FullSlideLibName As String
Public Sub Do_Menu_SlideLibrary()
Dim strFileName As String, SldFolder, strSlbName, ShellString As String
Dim FileNumber As Integer
Dim RetVal, RetValSlb As Variant
FullSlideLibName will hold the final outcome of this module - the slide library. The Sub is called from one of the menu items. StrFileName will store the filename with path of the slidelib.exe utility. SldFolder is the folder which contains all the slide (.sld) files. strSlbName will store the user specified slide library file name (.slb) ShellString will hold the stringthat we build to pass to the Shell function of VB. FileNumber is for the FreeFile function. And, RetVal and RetValSlb are temporary intermediate variables. |
|
Locate SlideLib.exe Ask the user to select the location of the SlideLib.exe utility that always sits in the Support folder of AutoCAD.
MsgBox "Locate and select slidelib.exe" & vbCrLf & vbCrLf & _
"( eg. in C:\Program Files\ACAD2000\Support )"
Form1.FileDlg.Flags = cdlOFNFileMustExist Or cdlOFNPathMustExist Or _
cdlOFNExplorer Or cdlOFNLongNames
Form1.FileDlg.Filter = "SlideLib Application (slidelib.exe)|*.exe"
Form1.FileDlg.FilterIndex = 1
Form1.FileDlg.ShowOpen
strFileName = Form1.FileDlg.FileName
Using the ShowOpen method of microsoft common dialog control, Store the SlideLib.exe file with full path in strFileName |
Get the Slides Folder and create a batch file
If strFileName = "" Then
MsgBox "Error : " & vbCrLf & vbCrLf & "* File Dialog cancelled, Or" & _
vbCrLf & vbCrLf & "* You did not select the slidelib.exe file _
after locating it."
Else
SldFolder = BrowseFolders("Select folder containing slide files.")
If SldFolder = "" Then
MsgBox "Error : No folder selected"
Else
FileNumber = FreeFile
Open SldFolder & "\" & "makelist.bat" For Output As #FileNumber
Print #FileNumber, "dir " & SldFolder & "\" & "*.sld > " & SldFolder & "\" & _
"sldlist.txt /b" & vbLf
Print #FileNumber, "exit" & vbLf
Close #FileNumber
Check if the string returned was zero length. There are two posibilites : 1. The user cancelled the file open dialog, or 2. The user located the support folder but did not actually pick the slidelib.exe file. Notify the user accordingly. If everything was ok, proceed to locate the folder where the slides are kept. This is done using the windows standard Browse for Folder dialog. The BrowseFolder function is defined in the foldbrow.bas module in the same project. Next, if the user cancels the dialog, prompt accordingly. If both the exe file and folder are located, make a batch file in the same folder, which writes a list of all sld files to a text file called sldlist.txt The VB statement that does this write the following lines to the batch file : dir X:\MySlidesFolder\*.sld > X:\MySlidesFolder\sldlist.txt |
Run the batch file
ChDir SldFolder
RetVal = Shell(SldFolder & "\" & "makelist.bat", vbHide)
If RetVal = 0 Then
MsgBox "Slide List creation failed !"
Else
strSlbName = InputBox("Specify filename for the slide library" & vbCrLf & _
"(without the .SLB extension).", "Create Slide Library", "MySlideLib")
If strSlbName = "" Or Trim(strSlbName) = "" Then
strSlbName = "MySlideLib"
End If
FileNumber = FreeFile
FileCopy strFileName, SldFolder & "\slidelib.exe"
Open SldFolder & "\" & "makelib.bat" For Output As #FileNumber
Print #FileNumber, SldFolder & "\slidelib.exe " & " " & SldFolder & "\" & _
strSlbName & " < " & "sldlist.txt" & vbLf
Print #FileNumber, "exit" & vbLf
Close #FileNumber
Change the current folder to the slides folder. Run the batch file using the Shell function. If the shell function succeeded, it returns a non-zero value to RetVal Ask the user file name for the slide library (.slb) file. If the user did not enter any name, set the default to MySlideLib Copy the SlideLib.exe file from AutoCAD folder to the slides folder. Write a batch file to do what you would other wise do manually at the DOS prompt : slidelib.exe MySlideLib.slb < SldList.txt This creates the slide library. |