- UID
- 5043
- 积分
- 1347
- 精华
- 贡献
-
- 威望
-
- 活跃度
-
- D豆
-
- 在线时间
- 小时
- 注册时间
- 2002-5-13
- 最后登录
- 1970-1-1
|
马上注册,结交更多好友,享用更多功能,让你轻松玩转社区。
您需要 登录 才可以下载或查看,没有账号?立即注册
×
This method allow a custom code to be executed when the user selects a keyword, which allow us include some additional keywords.
On the sample below, when acedSSGet() is called in a custom command, the user is able to use two new keywords: LInes to select all lines in the current drawing and CIRcles to select all circles. The callback function uses all possible return values.
First, check below the custom command, that register for the call back.
[it618postdisplay>0]
 - void MyCustomCommand()
- {
- // save the old callback function
- resbuf* (*oldFunc) (const ACHAR*);
- acedSSGetKwordCallbackPtr(&oldFunc);
- // set own callback function
- acedSSSetKwordCallbackPtr(ssCallback);
- // let the user make a selection
- ads_name ss;
- // this is the keyword list
- // to use local and global keywords:
- ACHAR kwordlist[] = { _T("LInes CIRcles _ LInes CIRcles") };
- if (RTNORM != acedSSGet(_T("_:K"), NULL, kwordlist, NULL, ss)) {
- // cancel
- } else {
- acutPrintf(_T("\nDone."));
- acedSSFree(ss);
- }
- // restore old callback function
- acedSSSetKwordCallbackPtr(*oldFunc);
- }
[/it618postdisplay]
Now the callback that is executed when the keyword is selected:
 - // Callback function for acedSSGet()
- resbuf* ssCallback(const TCHAR* kword)
- {
- // kword contains the global keyword
- acutPrintf(_T("\nCallback: '%s'"), kword);
- // result to return
- // NULL: no changes on selection set
- resbuf *result = NULL;
- if (!wcscmp(kword, _T("LInes"))) {
- // select all lines (just for testing)
- AcDbObjectIdArray objIds;
- getLines(objIds);
- // create resbuf containing single
- // enames from object id array
- result = getResbuf(objIds);
- } else if (!wcscmp(kword, _T("CIRcles"))) {
- // select all circles (just for testing)
- AcDbObjectIdArray objIds;
- getCircles(objIds);
- // create resbuf containing a selection set
- ads_name ss;
- acedSSGet(_T("X"), NULL, NULL,
- acutBuildList(RTDXF0, _T("CIRCLE"), RTNONE),
- ss);
- result = acutBuildList(RTPICKS, ss, RTNONE);
- } else {
- // return an error message
- result = acutBuildList(RTSTR, _T("\nUnknown error"), RTNONE);
- }
- return result;
- }
And finally some additional methods for this specific sample:
 - resbuf* getResbuf(AcDbObjectIdArray ids)
- {
- resbuf *result = NULL, *temp1, *temp2;
- ads_name ename;
- int length = ids.length();
- for (int i = 0; i < length; ++i) {
- acdbGetAdsName(ename, ids);
- temp2 = acutBuildList(RTENAME, ename, RTNONE);
- if (result == NULL) {
- result = temp2;
- } else {
- temp1->rbnext = temp2;
- }
- temp1 = temp2;
- }
- return result;
- }
- void getLines(AcDbObjectIdArray& ids)
- {
- // select all lines from model space
- // (without any error checking)
- AcDbBlockTable *pTable;
- AcDbBlockTableRecord *pModelSpace;
- AcDbBlockTableRecordIterator *pIter;
- AcDbEntity* pEnt;
- acdbHostApplicationServices()->workingDatabase()->
- getBlockTable(pTable, AcDb::kForRead);
- pTable->getAt(ACDB_MODEL_SPACE, pModelSpace, AcDb::kForRead);
- pTable->close();
- pModelSpace->newIterator(pIter);
- pModelSpace->close();
- for (; !pIter->done(); pIter->step()) {
- pIter->getEntity(pEnt, AcDb::kForRead);
- if (pEnt->isKindOf(AcDbLine::desc()))
- ids.append(pEnt->objectId());
- pEnt->close();
- }
- delete pIter;
- }
- void getCircles(AcDbObjectIdArray& ids)
- {
- // select all circles from model space
- // (without any error checking)
- AcDbBlockTable *pTable;
- AcDbBlockTableRecord *pModelSpace;
- AcDbBlockTableRecordIterator *pIter;
- AcDbEntity* pEnt;
- acdbHostApplicationServices()->workingDatabase()->
- getBlockTable(pTable, AcDb::kForRead);
- pTable->getAt(ACDB_MODEL_SPACE, pModelSpace, AcDb::kForRead);
- pTable->close();
- pModelSpace->newIterator(pIter);
- pModelSpace->close();
- for (; !pIter->done(); pIter->step()) {
- pIter->getEntity(pEnt, AcDb::kForRead);
- if (pEnt->isKindOf(AcDbCircle::desc()))
- ids.append(pEnt->objectId());
- pEnt->close();
- }
- delete pIter;
- }
|
|