Imports Autodesk
Imports Autodesk.AutoCAD.Interop
Imports Autodesk.AutoCAD.Interop.Common
imports Autodesk.AutoCAD.ApplicationServices
Imports Autodesk.AutoCAD.DatabaseServices
Imports Autodesk.AutoCAD.Runtime
Imports Autodesk.AutoCAD.Geometry
Imports System
Private Sub btnCircle_Click(ByVal sender As System.Object,ByVal e As System.EventArgs) Handles btnCircle.Click
'定义圆的圆心
Dim center As Point3d = New Point3d(100,100,0)
'定义圆的半径
Dim radius As Double = 50
'定义一个Circle对象来表示你要生成的圆,传入的第二个参数为圆的法向,
'就是把圆生、//成在什么面上,因为AutoCAD程序一般都是平面问题,
'因此你一般都把这个法向量定义成//z轴方向。
Dim circle As Circle
circle = New Circle(center,New Vector3d(0,1),radius)
Dim bt As BlockTable
Dim btr As BlockTableRecord
Dim db As Database
'获得当前活动AutoCAD文档所在的数据库
db = Application.DocumentManager.MdiActiveDocument.Database
'获得事务处理管理器
Dim tm As Autodesk.AutoCAD.DatabaseServices.TransactionManager
tm = db.TransactionManager
'定义事务处理
Dim trans As Transaction
Try
'开始事务处理,也就是往CAD中加入东西
trans = tm.StartTransaction
bt = tm.GetObject(db.BlockTableId,OpenMode.ForRead,False)
'获得块表记录
btr = tm.GetObject(bt(BlockTableRecord.ModelSpace),OpenMode.ForWrite,False)
'向块表记录加入圆的相关信息
btr.AppendEntity(Circle)
'向AutoCAD加入圆
tm.AddNewlyCreatedDBObject(Circle,True)
trans.Commit()
Catch ex As Exception
Throw New ApplicationException(ex.Message)
End Try
end sub
(参照了明经通道里的二次开发相关内容)