- UID
- 55121
- 积分
- 0
- 精华
- 贡献
-
- 威望
-
- 活跃度
-
- D豆
-
- 在线时间
- 小时
- 注册时间
- 2003-6-3
- 最后登录
- 1970-1-1
|
马上注册,结交更多好友,享用更多功能,让你轻松玩转社区。
您需要 登录 才可以下载或查看,没有账号?立即注册
×
用VBnet生成一个块,insert的时候总是提醒没关闭,Transaction自动关闭,不知哪个没有关闭,代码如下:
<Autodesk.AutoCAD.Runtime.CommandMethod("CREATEB")> _
Public Sub CreateEmployeeDefine()
Dim db As Database = HostApplicationServices.WorkingDatabase()
Dim trans As Transaction = db.TransactionManager.StartTransaction()
Try
Dim bt As BlockTable = trans.GetObject(db.BlockTableId, OpenMode.ForWrite)
Dim myBtr As BlockTableRecord = New BlockTableRecord()
myBtr.Name = "EmployeeBlock"
Dim myBtrId As ObjectId
myBtrId = bt.Add(myBtr)
Dim btr As BlockTableRecord = trans.GetObject(myBtrId, OpenMode.ForWrite)
Dim layerId As ObjectId = New ObjectId()
layerId = CreateLayer()
Dim center As Point3d = New Point3d(10, 10, 0)
'生成一个圆
Dim Circle As Circle = New Circle(center, Vector3d.ZAxis, 2.0)
Circle.LayerId = layerId
Circle.ColorIndex = 1
btr.AppendEntity(Circle)
'生成一个Mtext
Dim Mtext As MText = New MText()
Mtext.Contents = "lihengwang"
Mtext.Location = center
Mtext.LayerId = layerId
Mtext.ColorIndex = 2
btr.AppendEntity(Mtext)
'生成一个椭圆
Dim othPoint As Point3d = New Point3d(29, 3, 0)
Dim ellipse As Ellipse = New Ellipse(center, Vector3d.ZAxis, Vector3d.XAxis, 0.7, 0, 2 * 3.1415926535897)
ellipse.LayerId = layerId
Mtext.ColorIndex = 3
btr.AppendEntity(ellipse)
trans.AddNewlyCreatedDBObject(btr, True)
trans.Commit()
Catch
MsgBox("Error Adding Entities")
Finally
trans.Dispose()
End Try
End Sub |
|