cq_starsea 发表于 2015-1-29 16:05:35

怎样创建一个新块?

我要创建一个新块,块里面只有一个圆,我的代码如下,但是没创建起,请大家帮忙看看。谢谢!
    <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

sieben 发表于 2015-1-30 14:20:01

ModelSpace.AppendEntity(clr)

改为 btr.AppendEntity(clr)

sieben 发表于 2015-1-30 14:20:42

另外还要有 trans.AddNewlyCreatedDBObject(cir, True)

页: [1]
查看完整版本: 怎样创建一个新块?