Adding Attribute To A Block Definition
本帖最后由 newer 于 2021-1-11 20:44 编辑问题:
How can I add attribute to a block definition using ActiveX Automation API?
解答:
The code below shows how to add an Attribute to a block definition.
The following code creates block by name "test_block" and adds an attribute to it.
//use MFC
#import "acad.tlb" no_namespace
void fAddAttribute()
{
try
{
//first create a block and then add one attribute to it
//adding a block by name test_block
IAcadApplicationPtr pAcadApp = acedGetAcadWinApp()->GetIDispatch(TRUE);
IAcadDocumentPtr pActiveDoc = pAcadApp->ActiveDocument;
IAcadBlockPtr pBlock = NULL;
char *pBlkName;
pBlkName = "test_block";
VARIANT mvInsPt;
SAFEARRAYBOUND mSAB;
mSAB.lLbound = 0;
mSAB.cElements = 3;
mvInsPt.vt = VT_ARRAY | VT_R8;
mvInsPt.parray = SafeArrayCreate(VT_R8,1,&mSAB);
//fill the array of doubles for the insertion point
double mDbl;
mDbl = 0.0;mDbl = 0.0;mDbl = 0.0;
SafeArrayPutElement(mvInsPt.parray,0,(void *)&mDbl);
SafeArrayPutElement(mvInsPt.parray,0,(void *)&mDbl);
SafeArrayPutElement(mvInsPt.parray,0,(void *)&mDbl);
pBlock = pActiveDoc->Blocks->Add(mvInsPt,_bstr_t(pBlkName));
//block added
//add an Attribute to the block
IAcadAttributePtr pAttDef;
pAttDef = pBlock->AddAttribute(1.0, (AcAttributeMode)0 ,_bstr_t("Type the employee name"),mvInsPt,_bstr_t("empname"),_bstr_t(""));
//attribute added
}
catch(_com_error &es)
{
acutPrintf(""nError : %s", es.ErrorMessage());
}
}
附件是完整工程代码:
页:
[1]