shamsam1 发表于 2008-11-25 04:14:39

在同一个窗口vb.6代码中打开多个autocad文件

我有记事本,其中我指定了dwg文件的所有路径ex:
c:\fisrt.dwg
d:\folderr1\second.dwg
D:\aaaa\area.dwg
我正在寻找vb.6程序,它将在同一个窗口而不是单独的窗口中打开所有dwg绘图
**** Hidden Message *****

T.Willey 发表于 2008-11-25 11:04:19

你指的是同一个会话窗口吗
可以使用Lisp完成,因为这是Lisp论坛。如果需要VB6解决方案,可能需要移动此线程。

Rogue 发表于 2008-11-26 14:01:52

我惊讶地发现,使用“Acad.Application”的通用“getObject”调用不会返回当前正在运行的Acad实例。我必须在调用中指定版本才能获得正在运行的实例。否则,将启动
acad的*第二个*实例
下面的代码适用于我-我使用了“Acad.Application.17”,这是Autocad 2008。
我还将根目录中的图形名称调暗(将DwgToOpen调暗为字符串),当然,您会希望对其进行更改
这段代码是在Excel下创建的,不是VB6,我在这里没有它,但该死的,后期绑定就是后期绑定
技巧的一部分是调用getobject,不使用路径名参数,但使用逗号:
设置acApp=getobject(,“AutoCAD.Application.17”)
,如果acad未运行,则会在没有错误陷阱的情况下出错。因此,我们首先尝试该版本的调用,如果需要,捕获错误,然后,如果必须尝试调用的“标准”版本:
设置acApp=CreateObject(“AutoCAD.Application.17”)
以在找不到正在运行的实例时创建新实例。
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
页: [1]
查看完整版本: 在同一个窗口vb.6代码中打开多个autocad文件