TA的每日心情 | 开心 昨天 06:36 |
---|
签到天数: 15 天 [LV.4]偶尔看看III
管理员
- 积分
- 1308
|
- 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<i>);
- 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;
- }
复制代码 |
|