解决VB.NET外部调用CAD问题
搜索很多.net外部调用CAD的例子,基本都是用C写的,对于刚从VB转入.NET的小白来说很难看懂,下面是自己经过实践整理出来的VB.NET外部调用AutoCAD2018的例子。VB.net使用com对象实现外部调用CAD首先新建一个VB.NET项目,目标框架选择“.NET Framework 4.6”;添加对“AutoCAD 2018 Type Library”和“AutoCAD/ObjectDBX Common 22.0 Type Library”的引用,同时导入命名空间 :Imports AutoCAD;添加一个Form和一个Button按钮,一下代码直接复制即可测试,亲测可用,觉得有用记得点赞,谢谢。
Public Class Form1
Public Sub OpenACAD()'打开CAD
Dim myAcadApp As AutoCAD.AcadApplication, activeDoc As AutoCAD.AcadDocument, acMS As AutoCAD.AcadModelSpace
Dim msg As String
Try
myAcadApp = GetObject(, "Autocad.Application.22") '检查AutoCAD是否已经打du开
Catch
Try
myAcadApp = CreateObject("Autocad.Application.22") '打开2018CAD
Catch ex As Exception
msg = String.Format("{0}ralsed exception :{1}", ex.Source, ex.Message)
MessageBox.Show(msg, "My App", MessageBoxButtons.OK, MessageBoxIcon.Error)
End Try
End Try
If myAcadApp IsNot Nothing Then
myAcadApp.Visible = True '显示CAD
End If
End Sub
Private Sub Button1_Click(sender As Object, e As EventArgs) Handles Button1.Click
Call OpenACAD() '打开CAD
End Sub
End Class
https://converter.telerik.com/
http://www.carlosag.net/Tools/CodeTranslator/
会对你有帮助的
页:
[1]