怎样创建一个新块?
我要创建一个新块,块里面只有一个圆,我的代码如下,但是没创建起,请大家帮忙看看。谢谢!<CommandMethod("A2")>
Public Sub A2()
Dim doc As Autodesk.AutoCAD.ApplicationServices.Document = Autodesk.AutoCAD.ApplicationServices.Application.DocumentManager.MdiActiveDocument
Dim db As Database = doc.Database
Dim blockName As String = "asdsadsa"
Using trans As Transaction = db.TransactionManager.StartTransaction
Dim ModelSpace As BlockTableRecord = trans.GetObject(db.CurrentSpaceId, OpenMode.ForWrite)
Dim bt As BlockTable = trans.GetObject(db.BlockTableId, OpenMode.ForWrite)
Dim btr As BlockTableRecord = New BlockTableRecord()
If Not bt.Has(blockName) Then
btr.Name = blockName
Dim clr As New Circle
clr.Center = New Point3d(100, 100, 0)
clr.Radius = 40
ModelSpace.AppendEntity(clr)
bt.UpgradeOpen()
bt.Add(btr)
trans.AddNewlyCreatedDBObject(btr, True)
bt.DowngradeOpen()
End If
trans.Commit()
End Using
End Sub
ModelSpace.AppendEntity(clr)
改为 btr.AppendEntity(clr)
另外还要有 trans.AddNewlyCreatedDBObject(cir, True)
页:
[1]