找回密码
 立即注册

QQ登录

只需一步,快速开始

搜索
热搜: 活动 交友 discuz
查看: 156|回复: 0

[每日一码] Using acedSSSetKwordCallbackPtr on selections

[复制链接]

1

主题

0

回帖

33

积分

管理员

积分
33
发表于 2024-3-14 20:59:37 | 显示全部楼层 |阅读模式
  1. void MyCustomCommand()
  2. {
  3.   // save the old callback function
  4.   resbuf* (*oldFunc) (const ACHAR*);
  5.   acedSSGetKwordCallbackPtr(&oldFunc);
  6.   // set own callback function
  7.   acedSSSetKwordCallbackPtr(ssCallback);
  8.   // let the user make a selection
  9.   ads采用name ss;
  10.   // this is the keyword list
  11.   // to use local and global keywords:
  12.   ACHAR kwordlist[] = { 采用T("LInes CIRcles 采用 LInes CIRcles") };
  13.   if (RTNORM != acedSSGet(采用T("采用:K"), NULL, kwordlist, NULL, ss)) {
  14.     // cancel
  15.   } else {
  16.     acutPrintf(采用T("\nDone."));
  17.     acedSSFree(ss);
  18.   }
  19.   // restore old callback function
  20.   acedSSSetKwordCallbackPtr(*oldFunc);
  21. }
  22. [/it618postdisplay]
  23. Now the callback that is executed when the keyword is selected:
  24. 普通浏览复制代码
  25. // Callback function for acedSSGet()
  26. resbuf* ssCallback(const TCHAR* kword)
  27. {
  28.   // kword contains the global keyword
  29.   acutPrintf(采用T("\nCallback: '%s'"), kword);
  30.   // result to return
  31.   // NULL: no changes on selection set
  32.   resbuf *result = NULL;
  33.   if (!wcscmp(kword, 采用T("LInes"))) {
  34.     // select all lines (just for testing)
  35.     AcDbObjectIdArray objIds;
  36.     getLines(objIds);
  37.     // create resbuf containing single
  38.     // enames from object id array
  39.     result = getResbuf(objIds);
  40.   } else if (!wcscmp(kword, 采用T("CIRcles"))) {
  41.     // select all circles (just for testing)
  42.     AcDbObjectIdArray objIds;
  43.     getCircles(objIds);
  44.     // create resbuf containing a selection set
  45.     ads采用name ss;
  46.     acedSSGet(采用T("X"), NULL, NULL,
  47.       acutBuildList(RTDXF0, 采用T("CIRCLE"), RTNONE),
  48.       ss);
  49.     result = acutBuildList(RTPICKS, ss, RTNONE);
  50.   } else {
  51.     // return an error message
  52.     result = acutBuildList(RTSTR, 采用T("\nUnknown error"), RTNONE);
  53.   }
  54.   return result;
  55. }
  56. And finally some additional methods for this specific sample:
  57. 普通浏览复制代码
  58. resbuf* getResbuf(AcDbObjectIdArray ids)
  59. {
  60.   resbuf *result = NULL, *temp1, *temp2;
  61.   ads采用name ename;
  62.   int length = ids.length();
  63.   for (int i = 0; i < length; ++i) {
  64.     acdbGetAdsName(ename, ids<i>);
  65.     temp2 = acutBuildList(RTENAME, ename, RTNONE);
  66.     if (result == NULL) {
  67.       result = temp2;
  68.     } else {
  69.       temp1->rbnext = temp2;
  70.     }
  71.     temp1 = temp2;
  72.   }
  73.   return result;
  74. }
  75. void getLines(AcDbObjectIdArray& ids)
  76. {
  77.   // select all lines from model space
  78.   // (without any error checking)
  79.   AcDbBlockTable *pTable;
  80.   AcDbBlockTableRecord *pModelSpace;
  81.   AcDbBlockTableRecordIterator *pIter;
  82.   AcDbEntity* pEnt;
  83.   acdbHostApplicationServices()->workingDatabase()->
  84.     getBlockTable(pTable, AcDb::kForRead);
  85.   pTable->getAt(ACDB采用MODEL采用SPACE, pModelSpace, AcDb::kForRead);
  86.   pTable->close();
  87.   pModelSpace->newIterator(pIter);
  88.   pModelSpace->close();
  89.   for (; !pIter->done(); pIter->step()) {
  90.     pIter->getEntity(pEnt, AcDb::kForRead);
  91.     if (pEnt->isKindOf(AcDbLine::desc()))
  92.       ids.append(pEnt->objectId());
  93.     pEnt->close();
  94.   }
  95.   delete pIter;
  96. }
  97. void getCircles(AcDbObjectIdArray& ids)
  98. {
  99.   // select all circles from model space
  100.   // (without any error checking)
  101.   AcDbBlockTable *pTable;
  102.   AcDbBlockTableRecord *pModelSpace;
  103.   AcDbBlockTableRecordIterator *pIter;
  104.   AcDbEntity* pEnt;
  105.   acdbHostApplicationServices()->workingDatabase()->
  106.     getBlockTable(pTable, AcDb::kForRead);
  107.   pTable->getAt(ACDB采用MODEL采用SPACE, pModelSpace, AcDb::kForRead);
  108.   pTable->close();
  109.   pModelSpace->newIterator(pIter);
  110.   pModelSpace->close();
  111.   for (; !pIter->done(); pIter->step()) {
  112.     pIter->getEntity(pEnt, AcDb::kForRead);
  113.     if (pEnt->isKindOf(AcDbCircle::desc()))
  114.       ids.append(pEnt->objectId());
  115.     pEnt->close();
  116.   }
  117.   delete pIter;
  118. }
复制代码
您需要登录后才可以回帖 登录 | 立即注册

本版积分规则

Archiver|手机版|小黑屋|膜结构网

GMT+8, 2024-12-29 21:02 , Processed in 0.110199 second(s), 23 queries .

Powered by Discuz! X3.5

© 2001-2024 Discuz! Team.

快速回复 返回顶部 返回列表