I actually work with AutoCAD 2006 and Visual C# 2002.
Here is the description of my problem:
The last object that I insert in a drawing on the layer < 0 > is a block namely < Test >. This drawing has the layer name < Test > with the color yellow.
With the following code I can move the block from layer < 0 > to the layer < Test >. However I don't know how to recuperate the name of the block in the variable < info >. The name of the block that I received is < *Model_Space > rather than < Test >.
Anyone has the solution to my problem?
Thank you in advance.
[CommandMethod("TestBlk")]
static public void TestBlk()
{
Database db = HostApplicationServices.WorkingDatabase;
Editor ed = Autodesk.AutoCAD.ApplicationServices.Application.DocumentManager.MdiActiveDocument.Editor;
PromptSelectionResult result = ed.SelectLast();
Transaction trans = db.TransactionManager.StartTransaction();
try
{
ObjectId[]ids = result.Value.GetObjectIds();
Entity ent = (Entity)trans.GetObject(ids[0], OpenMode.ForWrite, false);
ent.Layer = "Test";
string info = GetBlockName(ent.ObjectId);
Autodesk.AutoCAD.ApplicationServices.Application.ShowAlertDialog(info);
trans.Commit();
}
finally
{
trans.Dispose();
}
}
static public string GetBlockName(ObjectId idRef)
{
using (Transaction t = idRef.Database.TransactionManager.StartTransaction())
{
BlockReference bref = (BlockReference)t.GetObject(idRef, OpenMode.ForRead);
BlockTableRecord btr = (BlockTableRecord)t.GetObject(bref.BlockId,OpenMode.ForRead);
return btr.Name;
}
}