Results 1 to 9 of 9

Thread: AutoCAD VBA DirListBox, FileListBox et DriveListBox

  1. #1
    Member
    Join Date
    2022-06
    Posts
    4
    Login to Give a bone
    0

    Default AutoCAD VBA DirListBox, FileListBox et DriveListBox

    Hello to everyone,

    I come back on a subject concerning an AutoCAD cartography routine which has not been solved and which still torments me...
    It seems that the problem comes of the loss of 32-bit OCX control since moving to VBA 7 and 32/64-bit platforms.

    When I run the routine, a DirListBox, a FileListBox and a DriveListBox should appear (see below on the left), but I get the window below on the right:

    image.png.7c4e5fa36168767e2999ebdd033fc08f.png image.png.579f2418e828d5e27e89752aff541f3f.png

    So I can't select my file for importing this famous .GDR file...

    Do you have any idea how to get these commands to appear? or replace them with a button maybe?

    I attach the .vbv file.

    Thank you in advance for your flashes of genius.

    Nicky
    Attached Files Attached Files

  2. #2
    Administrator Ed Jobe's Avatar
    Join Date
    2000-11
    Location
    Turlock, CA
    Posts
    6,399
    Login to Give a bone
    0

    Default Re: AutoCAD VBA DirListBox, FileListBox et DriveListBox

    That's a pretty archaic way of getting a file path. I recommend just using the Windows file dialogs api. I have a couple of classes for the FolderBrowse dialog and the FileBrowse dialog. I'll post them here later.
    C:> ED WORKING....

  3. #3
    Member
    Join Date
    2022-06
    Posts
    4
    Login to Give a bone
    0

    Default Re: AutoCAD VBA DirListBox, FileListBox et DriveListBox

    Hello Ed,

    Thank you to look into the situation!
    Indeed, these are old routines created by a friend of my associate who died several years ago... Since I'm trying to rerun them!

    Anyway, I'm waiting for your classes.

    Thanks very much

  4. #4
    Administrator Ed Jobe's Avatar
    Join Date
    2000-11
    Location
    Turlock, CA
    Posts
    6,399
    Login to Give a bone
    0

    Default Re: AutoCAD VBA DirListBox, FileListBox et DriveListBox

    Unzip the attached file (thanks to Alexander.Rivilis ) and Import the bas file into the Modules section of your project and then use the following code sample to call the browse folder dialog.
    Code:
    Public Sub GetFolderPath()
       Dim sPath As String
       sPath = BrowseFolder.FolderBrowse("Select Folder Containing Block Library", CurDir)
       If sPath <> "" Then
          If BrowseFolder.FolderExists(sPath) Then
             MsgBox sPath
          End If
       End If
    End Sub
    The code below shows how to use the FileDialogs class.
    Code:
    Public Sub OpenFile()
        'sample to show how to use FileDialogs
        Dim objFile As FileDialogs
        Dim strFilter As String
        Dim strFileName As String
    
        Set objFile = New FileDialogs
        objFile.OwnerHwnd = ThisDrawing.HWND32
        'desc,filter combinations must all be separated with pipe char "|"
        strFilter = "Drawings (*.dwg)|*.dwg|All Files (*.*)|*.*"
        objFile.Title = "Open a drawing"
        'default dir is CurDir
        objFile.StartInDir = "c:\"
        objFile.Filter = strFilter
        'return a valid filename
        strFileName = objFile.ShowOpen
        If Not strFileName = vbNullString Then
            'use this space to perform operation
            MsgBox strFileName
        End If
        Set objFile = Nothing
    
    End Sub
    Attached Files Attached Files
    C:> ED WORKING....

  5. #5
    Member
    Join Date
    2022-06
    Posts
    4
    Login to Give a bone
    0

    Default Re: AutoCAD VBA DirListBox, FileListBox et DriveListBox

    Hello Ed,

    Thank you very much for the files and codes.
    Unfortunately, my VBA comprehension and writing skills are very limited compared to LISP.

    I am learning the basics of VBA. Could you give me a little more detail on the procedure?
    Should I use the FileDialogs.cls file?

    Thanks in advance,

  6. #6
    Administrator Ed Jobe's Avatar
    Join Date
    2000-11
    Location
    Turlock, CA
    Posts
    6,399
    Login to Give a bone
    0

    Default Re: AutoCAD VBA DirListBox, FileListBox et DriveListBox

    save the files to disc and unzip them. Then open the VBAIDE, and in the project tree on the left, right click on the Modules section and select Import Module. Then select the bas file. Now right click on the Classes section and import the cls file. Now you can use the code. I believe there are code samples in them.
    C:> ED WORKING....

  7. #7
    Member
    Join Date
    2022-06
    Posts
    4
    Login to Give a bone
    0

    Default Re: AutoCAD VBA DirListBox, FileListBox et DriveListBox

    Ok, I understood that. What I don't understand is how to make the link between Module (browse folder dialog) and the FileDialogs class (OpenFile).

    Where should I paste the codes?
    I paste the GetFolderPath code on the "OPEN" CommandButton in my Form?
    How to call OpenFile afterwards?

  8. #8
    Administrator Ed Jobe's Avatar
    Join Date
    2000-11
    Location
    Turlock, CA
    Posts
    6,399
    Login to Give a bone
    0

    Default Re: AutoCAD VBA DirListBox, FileListBox et DriveListBox

    Maybe you should start by explaining what you want to do.

    Here's a command I wrote that uses the FileDialogs. It imports save views from a template into the current dwg.
    Code:
    Public Sub ImportViews()
        On Error GoTo ErrHandler:
        Dim strAppPath As String
        Dim objFile As FileDialogs
        Dim strFilter As String
        Dim strFileName As String
        Dim strTempName As String
        Dim fso As Scripting.FileSystemObject
        Dim fsoFile As Scripting.file
        Dim objView As AcadView
        Dim dbxdoc As Object 'AxDbDocument
        Dim colSelected As Collection
        
        Set fso = CreateObject("Scripting.FileSystemObject")
        strAppPath = ThisDrawing.Application.Preferences.Files.TemplateDwgPath
        Set objFile = New FileDialogs
        'desc,filter combinations must all be separated with pipe char "|"
        strFilter = "Templates (*.dwt)|*.dwt|Drawings (*.dwg)|*.dwg"
        objFile.OwnerHwnd = ThisDrawing.hWnd    'bind the dialog to the window
        objFile.Title = "Select file to views from."
        objFile.StartInDir = strAppPath
        objFile.Filter = strFilter
        'return a valid filename
    GetFile:
        strFileName = objFile.ShowOpen
        If Not strFileName = vbNullString Then
            'check for dwt, ObjectDbx can only open dwg's
            If fso.GetExtensionName(strFileName) = "dwt" Then
                'copy template to temp folder as dwg
                strTempName = ThisDrawing.Application.Preferences.Files.TempFilePath & fso.GetBaseName(strFileName) & ".dwg"
                fso.CopyFile strFileName, strTempName, True
                strFileName = strTempName
            End If
            'use ObjectDbx to get page setups in the background
            'open dbxdoc
            Set dbxdoc = AcadApplication.GetInterfaceObject("ObjectDBX.AxDbDocument")
            dbxdoc.Open strFileName
            'get a list of plot configs to import
            Set frmImportViews.Views = dbxdoc.Views
            frmImportViews.FillLists
            frmImportViews.Show
            Set colSelected = frmImportViews.SelectedViews
            If colSelected.Count = 0 Then Exit Sub
            Unload frmImportViews
            'copy the views from the template
            For Each objView In colSelected
                ThisDrawing.Views.Add objView.Name
            Next objView
            Set dbxdoc = Nothing
            'delete temp file if exists
            If Not strTempName = vbNullString Then fso.DeleteFile strTempName
        Else    'user clicked cancel in file dialog
        End If
        Set objFile = Nothing
        Set fso = Nothing
        Exit Sub
        
    ErrHandler:
        Select Case Err.Number
        Case Is = 70, Is = -2147467259
            MsgBox Err.Number & " - " & Err.Description & vbCrLf & "File may be in use or read-only.", vbCritical, "Import Views"
            GoTo GetFile
        Case Else
            MsgBox Err.Number & " - " & Err.Description, vbCritical, "Import Views"
        End Select
        
        
    End Sub
    Last edited by Ed Jobe; 2022-06-20 at 07:34 PM.
    C:> ED WORKING....

  9. #9
    Administrator Ed Jobe's Avatar
    Join Date
    2000-11
    Location
    Turlock, CA
    Posts
    6,399
    Login to Give a bone
    0

    Default Re: AutoCAD VBA DirListBox, FileListBox et DriveListBox

    I forgot about your dialog at the beginning of this thread. Just add the code to open the dialog in the OnClick method of your Open button. I don't understand all that your dialog is supposed to do. The FileDialogs class just gets a string for the path of the selected file. You can use that with the Shell Object or the AcadApplication.Documents collection to open it.
    C:> ED WORKING....

Similar Threads

  1. CP41-1L: VBA: Hands-On Introduction to VBA Programming
    By Autodesk University in forum Customization and Programming
    Replies: 0
    Last Post: 2013-04-17, 04:46 AM
  2. CP22-1L: VBA: Hands-On Introduction to VBA Programming
    By Autodesk University in forum Customization and Programming
    Replies: 0
    Last Post: 2013-04-17, 04:20 AM
  3. CP12-1L: VBA: Hands-On Introduction to VBA Programming
    By Autodesk University in forum Customization and Programming
    Replies: 0
    Last Post: 2013-04-17, 04:12 AM
  4. Replies: 5
    Last Post: 2007-04-30, 08:14 PM
  5. Newbie: Good AutoCAD/VBA book title?
    By rmshipp in forum VBA/COM Interop
    Replies: 3
    Last Post: 2004-09-30, 10:23 AM

Tags for this Thread

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •