|
[code]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);
}
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;
}[/code] |
|