你好,Kerry,
请参阅附件中的示例图。
我需要用数字扩展名重命名我的绘图中的一些块。
这不是问题,因为我下面的代码做得很好。
但是当我清除我的绘图时,所有重命名的块都消失了。
我不知道我是否正确使用了“DeepClone”方法。
有人能帮我解决这个问题吗?
欢迎所有建议。
提前谢谢您。
-
- Public Sub test()
- Dim zDoc As Document = Application.DocumentManager.MdiActiveDocument
- Dim zDb As Database = zDoc.Database
- Dim zEd As Editor = zDoc.Editor
- Using mTrans As Transaction = zDb.TransactionManager.StartTransaction()
- Try
- Dim mBlkTbl As BlockTable = mTrans.GetObject(zDb.BlockTableId, OpenMode.ForWrite)
- Dim zBlkTblRec As BlockTableRecord = mTrans.GetObject(mBlkTbl("test"), OpenMode.ForWrite)
- Dim i As Integer
- For Each zBlkTableRecId As ObjectId In zBlkTblRec.GetBlockReferenceIds(True, False)
- Dim BlkRef As BlockReference = mTrans.GetObject(zBlkTableRecId, OpenMode.ForWrite)
- Dim zMap As New IdMapping
- Dim newzBlkTblRec As BlockTableRecord = zBlkTblRec.DeepClone(mBlkTbl, zMap, True)
- newzBlkTblRec.Name = zBlkTblRec.Name & i
- BlkRef.BlockTableRecord = mBlkTbl.Add(newzBlkTblRec)
- mTrans.AddNewlyCreatedDBObject(newzBlkTblRec, True)
- i = i + 1
- Next
- Catch ex As SystemException
- MsgBox(ex.Message.ToString, MsgBoxStyle.Critical, "Rename block.")
- End Try
- mTrans.Commit()
- End Using
- End Sub
|