本次我们通过VB来设置文档窗口,文档窗口就是我们绘制图形的黑色区域。
1:设置文档大小
代码如下:
On Error Resume Next ' 连接至 AutoCAD 应用程序 Dim acadApp As AcadApplication Dim docObj As AcadDocument Set acadApp = GetObject(, "AutoCAD.Application.17.1") Set docObj = acadApp.Application.Documents.Add If Err Then Err.Clear Set acadApp = CreateObject("AutoCAD.Application.17.1") Set docObj = acadApp.Application.Documents.Add If Err Then MsgBox ("无法运行AutoCAD2008,请检查是否安装了AutoCAD2008") Exit Sub End If End If ' 连接至 AutoCAD 图形 Dim acadDoc As AcadDocument Set acadDoc = acadApp.ActiveDocument acadApp.Visible = True '设置文档大小 acadDoc.Application.WindowState = acMax acadDoc.Width = 600 acadDoc.Height = 600
2:文档最大化
代码如下:
On Error Resume Next ' 连接至 AutoCAD 应用程序 Dim acadApp As AcadApplication Dim docObj As AcadDocument Set acadApp = GetObject(, "AutoCAD.Application.17.1") Set docObj = acadApp.Application.Documents.Add If Err Then Err.Clear Set acadApp = CreateObject("AutoCAD.Application.17.1") Set docObj = acadApp.Application.Documents.Add If Err Then MsgBox ("无法运行AutoCAD2008,请检查是否安装了AutoCAD2008") Exit Sub End If End If ' 连接至 AutoCAD 图形 Dim acadDoc As AcadDocument Set acadDoc = acadApp.ActiveDocument acadApp.Visible = True '程序最大化 acadDoc.Application.WindowState = acMax '文档最大化 acadDoc.WindowState = acMax
效果如下:
3:文档最小化
代码如下:
On Error Resume Next ' 连接至 AutoCAD 应用程序 Dim acadApp As AcadApplication Dim docObj As AcadDocument Set acadApp = GetObject(, "AutoCAD.Application.17.1") Set docObj = acadApp.Application.Documents.Add If Err Then Err.Clear Set acadApp = CreateObject("AutoCAD.Application.17.1") Set docObj = acadApp.Application.Documents.Add If Err Then MsgBox ("无法运行AutoCAD2008,请检查是否安装了AutoCAD2008") Exit Sub End If End If ' 连接至 AutoCAD 图形 Dim acadDoc As AcadDocument Set acadDoc = acadApp.ActiveDocument acadApp.Visible = True '程序最大化 acadDoc.Application.WindowState = acMax '文档最大化 acadDoc.WindowState = acMin acadDoc.ZoomAll
效果如下:
4:查询文档状态
代码如下:
On Error Resume Next ' 连接至 AutoCAD 应用程序 Dim acadApp As AcadApplication Dim docObj As AcadDocument Set acadApp = GetObject(, "AutoCAD.Application.17.1") Set docObj = acadApp.Application.Documents.Add If Err Then Err.Clear Set acadApp = CreateObject("AutoCAD.Application.17.1") Set docObj = acadApp.Application.Documents.Add If Err Then MsgBox ("无法运行AutoCAD2008,请检查是否安装了AutoCAD2008") Exit Sub End If End If ' 连接至 AutoCAD 图形 Dim acadDoc As AcadDocument Set acadDoc = acadApp.ActiveDocument acadApp.Visible = True '程序最大化 acadDoc.Application.WindowState = acMax '文档最大化 acadDoc.WindowState = acMin '查询文档窗口状态 Dim CurrWindowState As Integer Dim msg As String CurrWindowState = acadDoc.WindowState msg = Choose(CurrWindowState, "常规", "最小化", "最大化") MsgBox "文档窗口状态为: " + msg
效果如下: