查无此鸟的博客 一个不误正业的交通工程师的个人网站

[博客园]【Hello AutoCAD 005】几个常用的绘图函数

标签:ACAD.NET | 发表时间:2010-11-24 12:43:00 | 更新时间: 2020-04-23 18:19:25 | 阅读数:215 | 评论数:0 | 字数:1885

注:本文2010-11-24首先发表于博客园,原地址为:https://www.cnblogs.com/transteel/archive/2010/11/24/1886411.html 。
1 '创建直线 2 Public Function addLine(ByVal startPt As Point3d, ByVal endPt As Point3d) As ObjectId 3 '在内存中创建一个直线对象 4 Dim LineEnt As New Line(startPt, endPt) 5 '调用AppendEntity函数,将直线加入到模型空间 6 Dim entID As ObjectId = AppendEntity(LineEnt) 7 Return entID 8 End Function 9 10 '创建圆 11 Public Function addCircle(ByVal cenPt As Point3d, ByVal Radius As Double) As ObjectId 12 '在内存中创建一个圆对象 13 Dim Ent As New Circle(cenPt, Vector3d.ZAxis, Radius) 14 Dim entID As ObjectId = AppendEntity(Ent) 15 Return entID 16 End Function 17 18 '创建圆弧【由圆心、半径、起始角度和终止角度创建圆弧】 19 Public Function addArc(ByVal cenPt As Point3d, ByVal Radius As Double, ByVal startAng As Double, ByVal endAng As Double) As ObjectId 20 '在内存中创建一个圆弧对象 21 Dim Ent As New Arc(cenPt, Radius, startAng, endAng) 22 Dim entID As ObjectId = AppendEntity(Ent) 23 Return entID 24 End Function 25 '由二维点集合和线宽创建二维优化多线段函数 26 Public Function addPline(ByVal Pts As Point2dCollection, ByVal Width As Double) As ObjectId 27 Try 28 '得到点集合的数量 29 Dim n As Integer = Pts.Count 30 '在内存中创建一个二维优化多线段对象 31 Dim Ent As New Polyline(n) 32 '向多线段添加顶点 33 For i As Integer = 0 To n - 1 34 Ent.AddVertexAt(i, Pts.Item(i), 0, Width, Width) 35 Next 36 Dim entID As ObjectId = AppendEntity(Ent) 37 Return entid 38 Catch ex As Exception 39 '创建失败,则返回一个空的ObjectId 40 Dim nullId As ObjectId = ObjectId.Null 41 Return nullId 42 End Try 43 End Function 44 45 '将图形对象加入到模型空间的函数 46 Public Function AppendEntity(ByVal Ent As Entity) As ObjectId 47 '得到当前文档的数据库对象 48 Dim Db As Database = HostApplicationServices.WorkingDatabase 49 Dim entID As ObjectId 50 Using Trans As Transaction = Db.TransactionManager.StartTransaction() 51 '以读方式打开块表 52 Dim Bt As BlockTable = CType(Trans.GetObject(Db.BlockTableId, OpenMode.ForRead), BlockTable) 53 '以写方式打开模型空间块表记录 54 Dim Btr As BlockTableRecord = CType(Trans.GetObject(Bt.Item(BlockTableRecord.ModelSpace), OpenMode.ForWrite), BlockTableRecord) 55 '将图形对象的信息加到块表记录中,并返回ObjectId对象 56 entID = Btr.AppendEntity(Ent) 57 '把直线添加到事物处理中 58 Trans.AddNewlyCreatedDBObject(Ent, True) 59 '提交事物处理 60 Trans.Commit() 61 End Using 62 Return entID 63 End Function

版权声明:本文由@查无此鸟创作,采用知识共享 署名-非商业性使用-禁止演绎 3.0 中国大陆许可协议进行许可。除非注明,均为原创文章,请在转载时注明来源,并完整保留本段声明。本文地址: http://liyonggang.net/blog.aspx?id= 2010-11-24



本文评论:
暂无评论……

发表评论:(昵称或评论内容不允许为空!邮箱可不填,但建议填写以备联系,邮箱将不显示在评论中。) 昵称 邮箱

查无此鸟的博客

Copyright©查无此鸟 2020~2022, All Rights Reserved

邮箱:t5lyg@126.com

其他链接

卢昌海的网站 | 鱼の后花园博客) | 新交通人的技术闲谈-知乎 | FROYOs Blog | 博客园 | 鸟哥Linux | 蜂鸟的小窝 | 大眼仔

AutoCAD.NET: Kevin K | 大非sb