Code:
[CommandMethod("Getentity2")]
public void EntityTest2()
{
Editor ed = Application.DocumentManager.MdiActiveDocument.Editor;
PromptEntityOptions entopts = new PromptEntityOptions("Objekt wählen");
entopts.Message = "Zeige ein Objekt deiner Wahl";
PromptEntityResult ent = null; try
{
ent = ed.GetEntity(entopts);
}
catch
{
ed.WriteMessage("Kein gültiges Objekt gewählt");
}
if (ent.Status != PromptStatus.Error)
{
ObjectId entid = ent.ObjectId;
Database db = Application.DocumentManager.MdiActiveDocument.Database;
Autodesk.AutoCAD.DatabaseServices.TransactionManager tm = db.TransactionManager;
using (Transaction myT = tm.StartTransaction())
{
Entity entity = (Entity)tm.GetObject(entid, OpenMode.ForRead);
//highlight the entity
ObjectId[] ids = new ObjectId[1];
ids[0] = entid;
SubentityId index = new SubentityId(SubentityType.Edge, 0);
FullSubentityPath path = new FullSubentityPath(ids, index);
entity.Highlight(path, true);
ed.WriteMessage("You selected: " + entity.GetType().FullName);
myT.Commit();
}
}
}