Hellow Everyone
I am trying to change a block name.
First a clone the block and then i want to change the block name from DOT to DOT2
Here is my part of code.I know is something with block record and new block record
Dim acBlkTbl As BlockTable
acBlkTbl = myT.GetObject(acCurDb.BlockTableId, OpenMode.ForRead)
Dim acBlkTblRec As BlockTableRecord
Dim blkname As String = "DOT2"
acBlkTblRec = myT.GetObject(acBlkTbl(BlockTableRecord.ModelSpace), OpenMode.ForWrite)
acBlkTblRec.Name = blkname
acBlkTbl.UpgradeOpen()
I know that something is wrong.
Please Help.Thankyou for your help
Solved! Go to Solution.
Solved by SENL1362. Go to Solution.
or in C#:
[CommandMethod("TestRenameBlock")] public void TestRenameBlock() { Document doc = Application.DocumentManager.MdiActiveDocument; Database db = doc.Database; Editor ed = doc.Editor; string oldBlockName = "DOT"; string newBlockName = "DOT2"; try { using (Transaction tr = db.TransactionManager.StartTransaction()) { BlockTable bt = (BlockTable)tr.GetObject(db.BlockTableId, OpenMode.ForRead); if (!bt.Has(oldBlockName)) throw new System.Exception(string.Format("Error: TestRenameBlock: Old Block not found: {0}", oldBlockName)); if (bt.Has(newBlockName)) throw new System.Exception(string.Format("Error: TestRenameBlock: New Block already exists: {0}", newBlockName)); BlockTableRecord oldBlock = (BlockTableRecord)tr.GetObject(bt[oldBlockName], OpenMode.ForRead); oldBlock.UpgradeOpen(); oldBlock.Name = newBlockName; tr.Commit(); } } catch (System.Exception ex) { ed.WriteMessage(ex.Message); } }
Can't find what you're looking for? Ask the community or share your knowledge.