VB Open Multiple CAD Drawings

Discussion in 'AutoCAD' started by LouDog, Jan 13, 2005.

  1. LouDog

    LouDog Guest

    I am a VB beginner looking for some assistance.
    I am trying to develop a code that can open multiple dwg's and plot
    them using my defined Page-setups. I manage to get VB to open a single
    dwg file in a defined location (C:\temp) but I cannot make VB to open
    multiple drawings. How can I accomplish this?
    Any suggestions will be greatly appreciated. I am running AutoCAD 2002
    and VB-6.

    Private Sub CmdRun_Click()

    Dim acad As AutoCAD.AcadApplication
    Dim dwg As AcadDocument

    Set acad = New AutoCAD.AcadApplication
    acad.Visible = False

    Set dwg = acad.Documents.Open("c:\temp\007.dwg")
    dwg.Close True
    acad.Quit

    End Sub

    Thanks,
    LouDog
     
    LouDog, Jan 13, 2005
    #1
  2. LouDog

    CS Guest

    I do this through Excel In Excel I keep a list of Drawing numbers that are
    in structured storage
    The code develops the path and opens the drawing prints it and closes the
    drawing then moves on to the next dwg.

    Try this

    Private Sub CmdRun_Click()
    Dim i As Variant
    Dim DwgList As New Collection
    Dim FileName As String
    Dim acad As AutoCAD.AcadApplication
    Dim dwg As AcadDocument

    FileName = "C:\Temp1.dwg"
    DwgList.Add FileName
    FileName = "C:\Temp2.dwg"
    DwgList.Add FileName
    FileName = "C:\Temp3.dwg"
    DwgList.Add FileName
    FileName = "C:\Temp4.dwg"
    DwgList.Add FileName
    FileName = "C:\Temp5.dwg"
    DwgList.Add FileName
    Set acad = New AutoCAD.AcadApplication
    acad.Visible = False

    For Each i In DwgList
    'loop through the drawings open them if successful tell the user
    Set dwg = Nothing
    On Error Resume Next
    Set dwg = acad.Documents.Open(i)
    On Error GoTo 0
    If dwg Is Nothing Then
    MsgBox "Failed to open " & i
    Else
    MsgBox "Opened " & i
    'code here to use your print settings
    dwg.Close True
    End If

    Next

    acad.Quit

    End Sub
     
    CS, Jan 13, 2005
    #2
  3. What do you mean by "open multiple drawings" ?
    If you want to open several drawings at the same time, you can use the .Open
    method mor than ione time:

    =====================================
    Dim acad As AutoCAD.AcadApplication
    Dim dwg(1 To 10) As AutoCAD.AcadDocument

    Set acad = New AutoCAD.AcadApplication
    acad.Visible = False

    Set dwg(7) = acad.Documents.Open("c:\temp\007.dwg")
    Set dwg(9) = acad.Documents.Open("c:\temp\077.dwg")
    Set dwg(2) = acad.Documents.Open("c:\temp\707.dwg")
    Set dwg(4) = acad.Documents.Open("c:\temp\770.dwg")

    dwg(9).Close True
    dwg(4).Close True
    dwg(7).Close True
    dwg(2).Close True
    acad.Quit
    =====================================

    Hope this helps.

    Johan.
     
    Johan Bechthum, Jan 13, 2005
    #3
Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments (here). After that, you can post your question and our members will help you out.