找回密码
 立即注册

QQ登录

只需一步,快速开始

扫一扫,访问微社区

查看: 1220|回复: 1

[求助]:图块清理(Purge)的问题

[复制链接]
发表于 2004-3-22 13:47:13 | 显示全部楼层 |阅读模式

马上注册,结交更多好友,享用更多功能,让你轻松玩转社区。

您需要 登录 才可以下载或查看,没有账号?立即注册

×
通常CAD图形中的图块,如果未被引用,可以被purge清理掉,以节省磁盘空间,但有某些块虽未被引用,我仍然需要保留在图形,不让其被清理,可何做到!
论坛插件加载方法
发帖求助前要善用【论坛搜索】功能,那里可能会有你要找的答案;
如果你在论坛求助问题,并且已经从坛友或者管理的回复中解决了问题,请把帖子标题加上【已解决】;
如何回报帮助你解决问题的坛友,一个好办法就是给对方加【D豆】,加分不会扣除自己的积分,做一个热心并受欢迎的人!

已领礼包: 145个

财富等级: 日进斗金

发表于 2004-3-22 14:01:31 | 显示全部楼层

Re: [求助]:图块清理(Purge)的问题

最初由 LQH 发布
[B]通常CAD图形中的图块,如果未被引用,可以被purge清理掉,以节省磁盘空间,但有某些块虽未被引用,我仍然需要保留在图形,不让其被清理,可何做到! [/B]


你可以使用反应器:

  1. AcEditorReactor::commandWillStart Function virtual void

  2. commandWillStart(

  3. const char* cmdStr);

  4. cmdStr Passed in string of the command being executed

  5. This callback function indicates that the command cmdStr is about to

  6. begin execution.

  7. cmdStr may be up to 257 characters (including the string terminator).



来判断是否执行了purge 命令,然后你保存你需要的“未被引用”的BLOCK,等AcEditorReactor::commandEnded  时候,你再恢复那些BLOCK到数据库。

具体可以看联机帮助和ARX目录下面的SAMPLE目录下的例子。

下面摘自联机帮助,介绍AcEditorReactor::commandEnded



  1. AcEditorReactor::commandEnded Function virtual void

  2. commandEnded(

  3. const char* cmdStr);

  4. cmdStr Passed in string of the command being executed

  5. This callback function indicates that the command cmdStr has completed.


  6. cmdStr may be up to 257 characters (including the string terminator).


  7. With commands involving sets of entities, and when
  8. AcEditorReactor::comandEnded() notification is sent, the last entity

  9. operated upon is still open for read even though AutoCAD is no longer
  10. looking at it. This prevents that entity from being opened for write via
  11. acdbOpenObject() within the notification callback.

  12. There are two ways to get around this limitation:

  13. 1  The preferred method is to use a transaction to manipulate the entities
  14. within your implementation of the commandEnded(). This bypasses any
  15. problems opening objects that are still open.

  16. Warning When using this method, you must be sure to end or terminate

  17. the transaction before you return from the commandEnded() function.

  18. Following is a simple example of this method:

  19. void
  20. AsdkEdReactor::commandEnded(const char *pCommand)
  21. {
  22.     // If AutoCAD is shutting down, then do nothing.
  23.     //
  24.     if (!acdbHostApplicationServices()->working Database())
  25.         return;

  26.     // get entities just operated on
  27.     //
  28.     ads_name sset;
  29.     int err = acedSSGet("p", NULL, NULL, NULL, sset);
  30.     if (err != RTNORM) {
  31.         acutPrintf("\nError acquiring previous selection set");
  32.         return;
  33.     }
  34.     actrTransactionManager->startTransaction();

  35.     long length;
  36.     acedSSLength(sset, &length);

  37.     ads_name en;
  38.     AcDbObjectId eId;
  39.     AcDbEntity *pEnt;
  40.     for (long i=0; i <  length; i++) {
  41.         acedSSName(sset, i, en);

  42.         Acad::ErrorStatus es = acdbGetObjectId(eId, en);
  43.         if (es != Acad::eOk) {
  44.             acutPrintf("\nacdbGetObjectId failed: "
  45.                 "Entity name < %lx,%lx >, error %s.", en[0], en[1],
  46.                 acadErrorStatusText(es));
  47.             acedSSFree(sset);
  48.             return;
  49.         }
  50.         es = actrTransactionManager->getObject((AcDbObject*&)pEnt,
  51.             eId, AcDb::kForWrite);
  52.         if (es == Acad::eOk) {
  53.             pEnt->setColorIndex(1);
  54.             pEnt->close();
  55.         } else {
  56.             acutPrintf("\ngetObject failed with error %s.",
  57.                 acadErrorStatusText(es));
  58.             actrTransactionManager->abortTransaction();
  59.             acedSSFree(sset);
  60.             return;
  61.         }
  62.     }
  63.     actrTransactionManager->endTransaction();
  64.     acedSSFree(sset);
  65. }
  66. 2  Within the commandEnded() implementation, you can open the entity
  67. for read and then repeatedly call its close() method until its isReallyClosing
  68. () method returns Acad::kTrue, indicating that there is now only one
  69. reader, and then use the entity's upgradeOpen() method to upgrade the
  70. open to AcDb::kForWrite.

  71. Now the entity is in a normal open AcDb::kForWrite state, so do whatever
  72. operations you want, followed by a call to the entity's close() or cancel()

  73. .
  74. Following is a simple example of this method:

  75. void
  76. AsdkEdReactor::commandEnded(const char *pCommand)
  77. {
  78.     // If AutoCAD is shutting down, then do nothing.
  79.     //
  80.     if (!acdbHostApplicationServices()->working Database())
  81.         return;
  82.    
  83.     // get entities just operated on
  84.     //
  85.     ads_name sset;
  86.     int err = acedSSGet("p", NULL, NULL, NULL, sset);
  87.     if (err != RTNORM) {
  88.         acutPrintf("\nError acquiring previous selection set");
  89.         return;
  90.     }

  91.     long length;
  92.     acedSSLength(sset, &length);

  93.     ads_name en;
  94.     AcDbObjectId eId;
  95.     AcDbEntity *pEnt;
  96.     for (long i=0; i < length; i++) {
  97.         acedSSName(sset, i, en);

  98.         Acad::ErrorStatus es = acdbGetObjectId(eId, en);
  99.         if (es != Acad::eOk) {
  100.             acutPrintf("\nacdbGetObjectId failed: "
  101.                 "Entity name < %lx,%lx >, error %s.", en[0], en[1],
  102.                 acadErrorStatusText(es));
  103.             acedSSFree(sset);
  104.             return;
  105.         }
  106.         es = acdbOpenObject(pEnt, eId, AcDb::kForWrite);
  107.         if (es == Acad::eOk) {
  108.             pEnt->setColorIndex(cindex);
  109.             pEnt->close();
  110.         } else if (es == Acad::eWasOpenForRead) {
  111.             // open it for read again to get a pointer to the
  112.             // entity and then close it repeatedly until it's
  113.             // down to one open for read.
  114.             //
  115.             acdbOpenObject(pEnt, eId, AcDb::kForRead);
  116.             do
  117.                 pEnt->close();
  118.             while (!pEnt->isReallyClosing());

  119.             // Now that we're down to one open for read, upgrade
  120.             // the open to kForWrite.
  121.             //
  122.             pEnt->upgradeOpen();

  123.             // do what we want and then close
  124.             //
  125.             pEnt->setColorIndex(1);
  126.             pEnt->close();
  127.         } else {
  128.             acutPrintf("\nacdbOpenObject failed with error %s.",
  129.                 acadErrorStatusText(es));
  130.             acedSSFree(sset);
  131.             return;
  132.         }
  133.     }
  134.     acedSSFree(sset);
  135. }
论坛插件加载方法
发帖求助前要善用【论坛搜索】功能,那里可能会有你要找的答案;
如果你在论坛求助问题,并且已经从坛友或者管理的回复中解决了问题,请把帖子标题加上【已解决】;
如何回报帮助你解决问题的坛友,一个好办法就是给对方加【D豆】,加分不会扣除自己的积分,做一个热心并受欢迎的人!
回复 支持 反对

使用道具 举报

您需要登录后才可以回帖 登录 | 立即注册

本版积分规则

QQ|申请友链|Archiver|手机版|小黑屋|辽公网安备|晓东CAD家园 ( 辽ICP备15016793号 )

GMT+8, 2024-9-21 13:27 , Processed in 0.287950 second(s), 33 queries , Gzip On.

Powered by Discuz! X3.5

© 2001-2024 Discuz! Team.

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