by Fenton Webb
The trick to doing this is to use the I*Ptr interfaces (e.g. IAcadDocumentPtr) so that COM reference counting is handled automatically.
Also, another trick is to stay away from VARIANT’s as much as possible, we have various AcAx* classes which help you do this… Here’s the code…
#import "acax19ENU.tlb" no_namespace #include #include void fAddAttribute() { try { // get the ActiveX application object from AutoCAD, inc ref count IAcadApplicationPtr pAcadApp = acedGetAcadWinApp()->GetIDispatch(TRUE); // now get the active doc IAcadDocumentPtr pActiveDoc = pAcadApp->ActiveDocument; IAcadBlockPtr pBlock = NULL; TCHAR *pBlkName = _T("some_block_name"); // create an activex compatible insertion point3d AcAxPoint3d axInsPnt(0,0,0); // now add the block name pBlock = pActiveDoc->Blocks->Add(axInsPnt.asVariantPtr(),_bstr_t(pBlkName)); // now add an Attribute to the block IAcadAttributePtr pAttDef; pAttDef = pBlock->AddAttribute(1.0, (AcAttributeMode)0 , _bstr_t("Type the employee name"), axInsPnt.asVariantPtr(), _bstr_t("empname"),_bstr_t("")); //attribute added } catch(_com_error &es) { acutPrintf(L"nError : %s", es.ErrorMessage()); } }

Leave a Reply