- 积分
- 3730
- 明经币
- 个
- 注册时间
- 2019-12-9
- 在线时间
- 小时
- 威望
-
- 金钱
- 个
- 贡献
-
- 激情
-
|
楼主 |
发表于 2022-10-8 08:36:40
|
显示全部楼层
- <CommandMethod("OffsetObject")>
- Public Sub OffsetObject()
- '' 获取当前文档和数据库
- Dim acDoc As Document = Application.DocumentManager.MdiActiveDocument
- Dim acCurDb As Database = acDoc.Database
- '' 启动事务
- Using acTrans As Transaction = acCurDb.TransactionManager.StartTransaction()
- '' 以读模式打开 Block 表
- Dim acBlkTbl As BlockTable
- acBlkTbl = acTrans.GetObject(acCurDb.BlockTableId, OpenMode.ForRead)
- '' 以写模式打开块表记录模型空间
- Dim acBlkTblRec As BlockTableRecord
- acBlkTblRec = acTrans.GetObject(acBlkTbl(BlockTableRecord.ModelSpace), OpenMode.ForWrite)
- '' 创建多段线
- Dim acPoly As Polyline = New Polyline()
- acPoly.AddVertexAt(0, New Point2d(1, 1), 0, 0, 0)
- acPoly.AddVertexAt(1, New Point2d(1, 2), 0, 0, 0)
- acPoly.AddVertexAt(2, New Point2d(2, 2), 0, 0, 0)
- acPoly.AddVertexAt(3, New Point2d(3, 2), 0, 0, 0)
- acPoly.AddVertexAt(4, New Point2d(4, 4), 0, 0, 0)
- acPoly.AddVertexAt(5, New Point2d(4, 1), 0, 0, 0)
- '' 添加新对象到块表记录和事务
- acBlkTblRec.AppendEntity(acPoly)
- acTrans.AddNewlyCreatedDBObject(acPoly, True)
- '' 偏移多段线给定距离
- Dim acDbObjColl As DBObjectCollection = acPoly.GetOffsetCurves(0.25)
- '' 遍历得到的新对象
- For Each acEnt As Entity In acDbObjColl
- '' 添加每个对象
- acBlkTblRec.AppendEntity(acEnt)
- acTrans.AddNewlyCreatedDBObject(acEnt, True)
- Next
- '' 保存新对象到数据库
- acTrans.Commit()
- End Using
- End Sub
已经在书中找到源码。完成了
|
|