Database acCurDb = Application.DocumentManager.MdiActiveDocument.Database;
using (Transaction acTrans = acCurDb.TransactionManager.StartTransaction())
{
var obj = acTrans.GetObject(id, OpenMode.ForRead);
if (obj is Entity)
{
// do stuff
}
acTrans.Commit();
}
if (Application.DocumentManager.Count > 0)
{
foreach(Document doc in Application.DocumentManager)
{
acCurDb = doc.Database;
break;
}
}
using (Transaction acTrans = acCurDb.TransactionManager.StartTransaction())
{
}
void IExtensionApplication.Initialize()
{
acApp.Idle += onIdle;
}
void IExtensionApplication.Terminate()
{
}
static bool isIdle = false;
private static void onIdle(object sender, EventArgs e)
{
acApp.Idle -= onIdle;
isIdle = true;
// <-- do something useful here
}
...
[CommandMethod("WatchDbEvents", CommandFlags.Session)]
public void WatchDbEvents()
{
do
{
if (isIdle == false)
{
Thread.Sleep(500);
}
} while (isIdle == false);
// do stuff here;
}