- 积分
- 10755
- 明经币
- 个
- 注册时间
- 2005-6-8
- 在线时间
- 小时
- 威望
-
- 金钱
- 个
- 贡献
-
- 激情
-
|
''' <summary>
''' 根据名称来炸碎块
''' </summary>
''' <param name="BlockName">块名称</param>
''' <param name="DeleteOrignialBlock">是否删除原来的块</param>
''' <returns></returns>
''' <remarks></remarks>
Public Function ExplodeBlock(ByVal BlockName As String, Optional ByVal DeleteOrignialBlock As Boolean = True) As Boolean
Using Trans As Transaction = DB.TransactionManager.StartTransaction
Dim BlkT As BlockTable = Trans.GetObject(DB.BlockTableId, OpenMode.ForRead)
If BlkT.Has(BlockName) Then
Dim BlkR As BlockTableRecord = Trans.GetObject(BlkT(BlockName), OpenMode.ForRead)
Dim ModelSpace As BlockTableRecord = Trans.GetObject(BlkT(BlockTableRecord.ModelSpace), OpenMode.ForWrite)
Dim IDs As ObjectIdCollection = BlkR.GetBlockReferenceIds(True, False)
Dim TempColl As New DBObjectCollection
For Each ID As ObjectId In IDs
Dim BlkRef As BlockReference = Trans.GetObject(ID, OpenMode.ForWrite)
BlkRef.Explode(TempColl)
For Each Ent As Entity In TempColl
ModelSpace.AppendEntity(Ent)
Trans.AddNewlyCreatedDBObject(Ent, True)
Next
TempColl.Clear()
If DeleteOrignialBlock Then
BlkRef.Erase()
End If
Next
ExplodeBlock = True
Else
ExplodeBlock = False
End If
Trans.Commit()
End Using
End Function
''' <summary>
''' 炸开图块
''' </summary>
''' <param name="IDs"></param>
''' <param name="DeleteOrignialBlock">是否删除原来的块</param>
''' <returns></returns>
''' <remarks></remarks>
Public Function ExplodeBlock(ByVal IDs() As ObjectId, Optional ByVal DeleteOrignialBlock As Boolean = True) As Boolean()
Dim bResult(IDs.Length - 1) As Boolean
Using Trans As Transaction = DB.TransactionManager.StartTransaction
Dim BlkT As BlockTable = Trans.GetObject(DB.BlockTableId, OpenMode.ForRead)
Dim BlkR As BlockTableRecord = Trans.GetObject(BlkT(BlockTableRecord.ModelSpace), OpenMode.ForWrite)
Dim obj As DBObject = Nothing, blk As BlockReference = Nothing
Dim TempColl As New DBObjectCollection
For I As Integer = 0 To IDs.Length - 1
obj = Trans.GetObject(IDs(I), OpenMode.ForWrite)
If TypeOf obj Is BlockReference Then
blk = obj
blk.Explode(TempColl)
For Each Ent As Entity In TempColl
BlkR.AppendEntity(Ent)
Trans.AddNewlyCreatedDBObject(Ent, True)
Next
If DeleteOrignialBlock Then
blk.Erase()
End If
bResult(I) = True
TempColl.Clear()
End If
Next
Trans.Commit()
End Using
ExplodeBlock = bResult
End Function
|
|