vb.net二次开发AutoCAD中画圆示例

前端之家收集整理的这篇文章主要介绍了vb.net二次开发AutoCAD中画圆示例前端之家小编觉得挺不错的,现在分享给大家,也给大家做个参考。

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

(参照了明经通道里的二次开发相关内容)

原文链接:https://www.f2er.com/vb/259590.html

猜你在找的VB相关文章