將一個塊添加到另一個塊中

Imports ZwSoft.ZwCAD.Runtime
Imports ZwSoft.ZwCAD.ApplicationServices
Imports ZwSoft.ZwCAD.DatabaseServices
Imports ZwSoft.ZwCAD.EditorInput


Public Class ZwcadApp
    <CommandMethod("test")> _
    Public Sub test()
        Dim ZcDoc As Document = Application.DocumentManager.MdiActiveDocument
        Dim ZcDB As Database = ZcDoc.Database
        Dim ZcEd As Editor = ZcDoc.Editor


        Using ZcTrans As Transaction = ZcDB.TransactionManager.StartTransaction()
            Dim ZcBT As BlockTable = ZcTrans.GetObject(ZcDB.BlockTableId, OpenMode.ForWrite)
            If ZcBT.Has("testA") And ZcBT.Has("testB") Then
                Dim ZcBLTRa As BlockTableRecord = ZcTrans.GetObject(ZcBT("testA"), OpenMode.ForWrite)
                Dim brf As BlockReference = New BlockReference(ZcBLTRa.Origin, ZcBLTRa.ObjectId)


                Dim ZcBTR As BlockTableRecord = DirectCast(ZcTrans.GetObject(ZcBT(BlockTableRecord.ModelSpace), OpenMode.ForWrite), BlockTableRecord)
                ZcBTR.AppendEntity(brf)
                ZcTrans.AddNewlyCreatedDBObject(brf, True)


                Dim ent As Entity = DirectCast(brf, Entity).Clone()
                Dim ZcBLTRb As BlockTableRecord = ZcTrans.GetObject(ZcBT("testB"), OpenMode.ForWrite)
                ZcBLTRb.AppendEntity(ent)
                ZcTrans.AddNewlyCreatedDBObject(ent, True)


                Dim newBrf As BlockReference = New BlockReference(ZcBLTRb.Origin, ZcBLTRb.ObjectId)
                ZcBTR.AppendEntity(newBrf)
                ZcTrans.AddNewlyCreatedDBObject(newBrf, True)


                brf.Erase()


            Else
                ZcEd.WriteMessage(vbLf & "A block with this name doesn't exist.")
            End If
            ZcTrans.Commit()
        End Using
    End Sub
End Class
發表評論
所有評論
還沒有人評論,想成為第一個評論的人麼? 請在上方評論欄輸入並且點擊發布.
相關文章