找回密码
 立即注册

QQ登录

只需一步,快速开始

扫一扫,访问微社区

查看: 1222|回复: 0

API for draworder command

[复制链接]

已领礼包: 40个

财富等级: 招财进宝

发表于 2021-1-8 12:39:57 | 显示全部楼层 |阅读模式

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

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

×


问题:
Is there an API available for the DRAWORDER command? How can my ARX application
do what DRAWORDER does without calling the DRAWORDER command with acedCommand?

解答:
The DRAWORDER command uses an undocumented class, AcDbSortentsTable. It is not
documented in the help files because the present mechanism is not in its intended
final form.

WARNING: If you use the code in this solution in your application, you run the
risk that you will need to change your application for future versions of AutoCAD.

Refer to the attached header file sorttab.h for the definition of the class
AcDbSortentsTable. This header needs to be copied and included in your projects.
The AcDbSortentsTable class object is stored under the key "ACAD_SORTENTS" in
the extension dictionary of a block table record.

The following code defines a command "SENDBACK" that sends a selected entity
into the background:



  1. //
  2. // Helpers for SENDBACK
  3. //
  4. AcDbSortentsTable*
  5. get_sortents_table_of( AcDbEntity *pEnt )
  6. {
  7.     AcDbObjectId owner_id = pEnt->ownerId();
  8.     if (AcDbObjectId::kNull == owner_id)
  9.         return NULL;


  10.     AcDbBlockTableRecord *pRec;
  11.     if (Acad::eOk != acdbOpenObject( pRec, owner_id, AcDb::kForRead ))
  12.         return NULL;


  13.     AcDbObjectId ext_id = pRec->extensionDictionary();
  14.     if (AcDbObjectId::kNull == ext_id)
  15.     {
  16.         if (Acad::eOk != pRec->upgradeOpen())
  17.         {
  18.             pRec->close();
  19.             return NULL;
  20.         }
  21.         pRec->createExtensionDictionary();
  22.         ext_id = pRec->extensionDictionary();
  23.         if (AcDbObjectId::kNull == ext_id)
  24.         {
  25.             pRec->close();
  26.             return NULL;
  27.         }
  28.     }


  29.     AcDbDictionary *pExt;
  30.     Acad::ErrorStatus es = acdbOpenObject( pExt, ext_id, AcDb::kForRead );


  31.     pRec->close();
  32.     if (Acad::eOk != es)
  33.         return NULL;


  34.     AcDbObject *pObj;
  35.     if (Acad::eOk != pExt->getAt( "ACAD_SORTENTS", pObj, AcDb::kForWrite ))
  36.     {
  37.         if (Acad::eOk != pExt->upgradeOpen())
  38.         {
  39.             pExt->close();
  40.             return NULL;
  41.         }
  42.         AcDbSortentsTable *pSt = new AcDbSortentsTable;
  43.         if (NULL == pSt)
  44.         {
  45.             pExt->close();
  46.             return NULL;
  47.         }


  48.         AcDbObjectId new_id;
  49.         if (Acad::eOk != pExt->setAt( "ACAD_SORTENTS", pSt, new_id ))
  50.         {
  51.             delete pSt;
  52.             pExt->close();
  53.             return NULL;
  54.         }
  55.         pSt->setBlockId( owner_id );
  56.         pObj = pSt;
  57.     }


  58.     pExt->close();


  59.     if (!pObj->isKindOf( AcDbSortentsTable::desc() ))
  60.     {
  61.         pObj->close();
  62.         return NULL;
  63.     }


  64.     return (AcDbSortentsTable*)pObj;
  65. }



  66. void
  67. setSortentsBits( int bits )
  68. {
  69.     resbuf rb;
  70.     rb.restype = RTSHORT;
  71.     rb.resval.rint = bits;
  72.     acedSetVar( "SORTENTS", &rb );
  73. }



  74. void
  75. configureSortents()
  76. {
  77.     resbuf rb;
  78.     const int nSortentsMask = (1 | 2 | 4 | 8 | 16 | 32 | 64);


  79.     acedGetVar( "SORTENTS", &rb );


  80.     if (nSortentsMask != (rb.resval.rint & nSortentsMask))
  81.         setSortentsBits( rb.resval.rint | nSortentsMask );
  82. }


  83. void ads_regen(); // undocumented func



  84. // This is command 'SENDBACK'
  85. void MSSendBack()
  86. {
  87.     ads_name ent;
  88.     ads_point pt;


  89.     if (RTNORM != acedEntSel( "\nSelect Entity: ", ent , pt ))
  90.         return;


  91.     AcDbObjectId ent_id;
  92.     if (Acad::eOk != acdbGetObjectId( ent_id, ent ))
  93.         return;


  94.     configureSortents();


  95.     AcDbEntity *pEnt;
  96.     if (Acad::eOk != acdbOpenObject( pEnt, ent_id, AcDb::kForRead ))
  97.         return;


  98.     AcDbSortentsTable *pSt = get_sortents_table_of( pEnt );


  99.     pEnt->close();
  100.     if (NULL == pSt)
  101.         return;


  102.     AcDbObjectIdArray entity_array;
  103.     entity_array.append( ent_id );


  104.     pSt->moveToBottom( entity_array );
  105.     pSt->close();


  106.     // Must do a full regen
  107.    ads_regen();
  108. }


头文件见附件
1613.zip (946 Bytes, 下载次数: 0, 售价: 30 D豆)

论坛插件加载方法
发帖求助前要善用【论坛搜索】功能,那里可能会有你要找的答案;
如果你在论坛求助问题,并且已经从坛友或者管理的回复中解决了问题,请把帖子标题加上【已解决】;
如何回报帮助你解决问题的坛友,一个好办法就是给对方加【D豆】,加分不会扣除自己的积分,做一个热心并受欢迎的人!
您需要登录后才可以回帖 登录 | 立即注册

本版积分规则

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

GMT+8, 2024-12-14 19:04 , Processed in 0.543423 second(s), 29 queries , Gzip On.

Powered by Discuz! X3.5

© 2001-2024 Discuz! Team.

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