- UID
- 5280
- 积分
- 9466
- 精华
- 贡献
-
- 威望
-
- 活跃度
-
- D豆
-
- 在线时间
- 小时
- 注册时间
- 2002-5-18
- 最后登录
- 1970-1-1
|
马上注册,结交更多好友,享用更多功能,让你轻松玩转社区。
您需要 登录 才可以下载或查看,没有账号?立即注册
×
本帖最后由 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[3];
- mDbl[0] = 0.0;mDbl[1] = 0.0;mDbl[2] = 0.0;
- SafeArrayPutElement(mvInsPt.parray,0,(void *)&mDbl[0]);
- SafeArrayPutElement(mvInsPt.parray,0,(void *)&mDbl[1]);
- SafeArrayPutElement(mvInsPt.parray,0,(void *)&mDbl[2]);
- 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());
- }
- }
-
附件是完整工程代码:
70209.zip
(173.7 KB, 下载次数: 0, 售价: 50 D豆)
|
|