using System;
using Autodesk.AutoCAD.Runtime;
using Autodesk.AutoCAD.ApplicationServices;
using Autodesk.AutoCAD.DatabaseServices;
using Autodesk.AutoCAD.Geometry;
using Autodesk.AutoCAD.EditorInput;
[CommandMethod("ALTERBLOCKNAME")]
public void AlterBlockName()
{
Document doc = Application.DocumentManager.MdiActiveDocument;
Editor ed = doc.Editor;
Database dbs=doc.Database;
PromptEntityOptions peo = new PromptEntityOptions("\n请选择块:");
peo .SetRejectMessage("\n选择的必须是块!");
peo .AddAllowedClass(typeof(BlockReference), false);
PromptEntityResult entRes = ed.GetEntity(peo);
if (entRes.Status != PromptStatus.OK)return;
using (DocumentLock dl = doc.LockDocument())
{
using (Transaction trans = doc.TransactionManager.StartTransaction())
{
BlockReference blkRef = (BlockReference)trans.GetObject(entRes.ObjectId, OpenMode.ForRead);
BlockTableRecord btr2 = (BlockTableRecord)trans.GetObject(blkRef.BlockTableRecord, OpenMode.ForWrite);
btr2.Name = "ABC";
trans.Commit();
}
}
}