- 积分
- 2615
- 明经币
- 个
- 注册时间
- 2010-7-27
- 在线时间
- 小时
- 威望
-
- 金钱
- 个
- 贡献
-
- 激情
-
|
发表于 2011-5-26 13:14:16
|
显示全部楼层
- Public Function CreateBlock() As ObjectId
- Dim db As Database = HostApplicationServices.WorkingDatabase
- '用于返回所创建的块的对象Id
- Dim blockId As ObjectId = ObjectId.Null
- '创建一个BlockTableRecord类的对象,表示所要创建的块
- Dim record As New BlockTableRecord()
- '设置块名
- record.Name = "Room"
- Using trans As Transaction = db.TransactionManager.StartTransaction()
- Dim points As New Point3dCollection() '用于表示组成块的多段线的顶点
- points.Add(New Point3d(-18.0, -6.0, 0.0))
- points.Add(New Point3d(18.0, -6.0, 0.0))
- points.Add(New Point3d(18.0, 6.0, 0.0))
- points.Add(New Point3d(-18.0, 6.0, 0.0))
- '创建组成块的多段线
- Dim pline As New Polyline2d(Poly2dType.SimplePoly, points, 0.0, True, 0.0, 0.0, Nothing)
- record.Origin = points(3) '设置块的基点
- record.AppendEntity(pline) '将多段线加入到新建的BlockTableRecord对象
- '以写的方式打开块表
- Dim bt As BlockTable = trans.GetObject(db.BlockTableId, OpenMode.ForWrite)
- If bt.Has("Room") = False Then '判断是否存在名为"Room"的块
- blockId = bt.Add(record) '在块表中加入"Room"块
- trans.AddNewlyCreatedDBObject(record, True) '通知事务处理
- trans.Commit() '提交事务
- End If
- End Using
- Return blockId '返回创建的块的对象Id
- End Function
|
|