The following sample illustrates how to retrieve the .Net managed object once we have access to its COM wrapper. The best way to achieve that is to use the old objectId property as below:
[CommandMethod("Com2DotNet")]
public static void Com2DotNet()
{
AcadApplication acadApp = Application.AcadApplication
as AcadApplication;
Object obj = new Object();
Object pt = new Object();
acadApp.ActiveDocument.Utility.GetEntity(
out obj,
out pt,
"\nPick an entity: ");
Autodesk.AutoCAD.Interop.Common.AcadEntity acadEntity = obj
as Autodesk.AutoCAD.Interop.Common.AcadEntity;
 
;
Document doc = Application.DocumentManager.MdiActiveDocument;
Database db = doc.Database;
Editor ed = doc.Editor;
using(Transaction Tx = db.TransactionManager.StartTransaction())
{
ObjectId id = new ObjectId((IntPtr)acadEntity.ObjectID);
Entity entity = Tx.GetObject(id, OpenMode.ForWrite)
as Entity;
entity.ColorIndex = 1;
Tx.Commit();
}
<
p style=”line-height: normal;margin: 0in 0in 0pt” class=”MsoNormal”>}

Leave a Reply