The common way to access AutoCAD interface object is GetActiveObject, but this may return null on certain scenarios, such as On_kInitAppMsg, and is not guaranteed to access the current AutoCAD.
Since the ObjectARX application is loaded into AutoCAD process space, there is no need to go to running object’s table to get the COM pointer. So we can get it directly using the following code snippet (which requires MFC support):
IAcadApplicationPtr pAcadApp;
IDispatch* pDispatch = acedGetAcadWinApp()->GetIDispatch(FALSE);
pDispatch->QueryInterface(__uuidof(IAcadApplication),
(void**)&pAcadApp);

Leave a Reply