前端之家收集整理的这篇文章主要介绍了
VB CAD插件二次开发,
前端之家小编觉得挺不错的,现在分享给大家,也给大家做个参考。
<pre name="code" class="vb">Dim acadapp As AcadApplication '在窗体代码声明段定义acadapp
Private Sub Command1_Click()
acadapp.Documents.Add '创建新的图形文件
End Sub
Private Sub Command2_Click()
Dim myfilename As String
Me.CommonDialog1.ShowOpen
myfilename = Me.CommonDialog1.FileName
If myfilename <> "" Then
acadapp.Documents.Open myfilename
End If
End Sub
Private Sub Command3_Click()
Dim savename As String
Me.CommonDialog1.ShowSave
savename = Me.CommonDialog1.FileName
If savename <> "" Then
acadapp.ActiveDocument.SaveAs savename
End If
End Sub
Private Sub Command4_Click()
If Not acadapp.ActiveDocument.Saved Then
If MsgBox("是否保存文件?",vbYesNo) = vbYes Then
acadapp.ActiveDocument.Save
End If
End If
End Sub
Private Sub Command5_Click()
acadapp.ActiveDocument.Close (True) '以当前文件名和路径保存修改后的图形文件,然后关闭文件,若为False则不修改即保存
End Sub
Private Sub Form_Load()
On Error Resume Next
Set acadapp = GetObject(,"autocad.application")
If Err Then
Err.Clear
Set acadapp = CreateObject("autocad.application")
If Err Then
MsgBox ("不能运行AutoCad,请检查是否安装了CAD")
Exit Sub
End If
End If
acadapp.Visible = True
End Sub