Author Topic: open multiple autocad file in same window vb.6 code  (Read 4762 times)

0 Members and 1 Guest are viewing this topic.

shamsam1

  • Guest
open multiple autocad file in same window vb.6 code
« on: November 25, 2008, 04:14:39 AM »

i have notepad in which i specify all path of the dwg file ex:
c:\fisrt.dwg
d:\folderr1\second.dwg
D:\aaaa\area.dwg

i am looking for  vb.6 program which will open all dwg drawings in same window instead of separate window :mrgreen:

T.Willey

  • Needs a day job
  • Posts: 5251
Re: open multiple autocad file in same window vb.6 code
« Reply #1 on: November 25, 2008, 11:04:19 AM »
Do you mean same session window?

Can be done with Lisp, since this is the Lisp forum.  If you want a VB6 solution, you may want to have this thread moved.
Tim

I don't want to ' end-up ', I want to ' become '. - Me

Please think about donating if this post helped you.

rogue

  • Guest
Re: open multiple autocad file in same window vb.6 code
« Reply #2 on: November 26, 2008, 02:01:52 PM »
I was surprised to see that the generic "getObject" call, using "Acad.Application", would NOT return the current running instance of acad. I had to specify the version in the call to get the running instance. Otherwise, a *second* instance of
acad was started.


The code below works for me  - I used "Acad.Application.17", which is Autocad 2008.
I also dimmed the name of a drawing in my root dir (Dim DwgToOpen As String), which you will want to change , of course.
 This code was created under Excel, not VB6, which I dont have handy here in work, but hell, late binding is late binding.

Part of the trick is to call getobject without the Pathname parameter , but WITH a comma:

Set acApp = GetObject(, "AutoCAD.Application.17")

which errors out without an error trap, if acad is not running. So we try that version of the call first, trap the error if needed, and then, if we have to try the 'standard' version of the call:

Set acApp = CreateObject("AutoCAD.Application.17")

to create a new instance if we cant find a running instance.


Code: [Select]
Sub Main()

    Dim acApp As Object
    ' make sure under "Tools|Options|General" you select "Break on Unhandled Errors" selected
   
    ' Dim a Dwg Name to open in acad
    Dim DwgToOpen As String: DwgToOpen = "c:\test.dwg"
   
   
    On Error Resume Next   ' call errors out if Acad 2008 not running
        ' get running instance of AutoCad
        Set acApp = GetObject(, "AutoCAD.Application.17")
    On Error GoTo 0
   
    ' if we dont have it, create from scratch
    If acApp Is Nothing Then   ' start new session of Autocad
        Set acApp = CreateObject("AutoCAD.Application.17")
       
        If acApp Is Nothing Then
            MsgBox "Unable to open Autocad 2008"
            Set acApp = Nothing
            Exit Sub
        Else
            MsgBox "We are running a new instance of acad 2008"
        End If
       
    Else
        MsgBox "We are using the current running Aacad 2008"
    End If
   
   
    ' well, we have an instance of acad ruinning, whether an already running version,
    ' or a new version. Open the drawing in acad, as read-only
   
  Dim MyDwg As Object
  Set MyDwg = acApp.Documents.Open(DwgToOpen, True)

End Sub