找回密码
 立即注册

QQ登录

只需一步,快速开始

扫一扫,访问微社区

查看: 981|回复: 0

[分享] Retrieving entity properties using AccoreConsole

[复制链接]

已领礼包: 859个

财富等级: 财运亨通

发表于 2015-7-22 18:56:38 | 显示全部楼层 |阅读模式

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

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

×
Retrieving entity properties using AccoreConsoleBy Balaji Ramamoorthy
The "dumpallproperties" is an easy way to list all the properties of an entity using Lisp. Unfortunately, this does not work when used in the script file along with AccoreConsole. A ** way to workaround this and display the entity properties in AccoreConsole, is to create a CRX plugin that uses the Non-COM property system to display the entity properties.
If you are new to the Non-COM property system, please refer to this blog post : DevTV : Non-COM Property System
The code in this blog post uses portions of the code from that DevTV in a CRX application. Here is the relevant code and the complete sample project can be downloaded here :
Download EntProps_CRX
static  void  ListEntityProperties(void ) {         TCHAR entityHandle[133];         if  (acedGetString(                 Adesk::kFalse,                  _T("\\nEnter entity handle : " ),                 entityHandle) != RTNORM)         {                 acutPrintf(ACRX_T("\\nInvalid entity handle." ));                 return ;         }         CUtils::DisplayProperties(entityHandle); }  void  initApp() {      acedRegCmds->addCommand(ACRX_T("MY_COMMANDS" ),                              ACRX_T("EntProps" ),                              ACRX_T("EntProps" ),                              ACRX_CMD_TRANSPARENT,                              ListEntityProperties);  }   #include  "rxmember.h" #include  "rxvaluetype.h" #include  "rxattrib.h" #include  "rxprop.h" #include  "dbobjptr.h"   // Utils.cpp void  CUtils::DisplayProperties(LPCTSTR handleStr) {         Acad::ErrorStatus es;         AcApDocument *pActiveDoc                  = acDocManager->mdiActiveDocument();         AcDbDatabase *pDB = pActiveDoc->database();          AcDbObjectId id = AcDbObjectId::kNull;         AcDbHandle objHandle(handleStr);     es = pDB->getAcDbObjectId(id, false , objHandle);     if  (es != Acad::eOk)         {         acutPrintf(                 _T("\\nCould not translate handle to objectId" ));     }          AcDbObjectPointer<AcDbEntity> entity(id, AcDb::kForRead);          AcRxMemberIterator * iter =                  AcRxMemberQueryEngine::theEngine()->newMemberIterator                 (entity);             for  (; !iter->done(); iter->next())         {                 printValues(entity, iter->current());         } }  void  CUtils::getAttInfo(         const  AcRxAttribute * att,         const  AcRxObject * member,         AcString & attInfo) {         if  (att->isA() == AcRxCOMAttribute::desc())         {                 AcRxCOMAttribute * a = AcRxCOMAttribute::cast(att);                 attInfo.format(_T("\\n%s - %s" ),                         att->isA()->name(), a->name());          }         else  if  (att->isA() == AcRxUiPlacementAttribute::desc())         {                 AcRxUiPlacementAttribute * a                          = AcRxUiPlacementAttribute::cast(att);                 attInfo.format(                 _T("\\n%s - %s - %f" ),                 att->isA()->name(),                  a->getCategory(member),                 a->getWeight(member));          }         else         {                 attInfo.format(_T("\\n%s" ), att->isA()->name());         } }  void  CUtils::printValues(         AcRxObject * entity,          const  AcRxMember * member) {         Acad::ErrorStatus err = Acad::eOk;          AcString strValue;         AcRxProperty * prop = AcRxProperty::cast(member);         if  (prop != NULL)         {                 AcRxValue value;                  if  ((err = prop->getValue(entity, value))                         == Acad::eOk)                  {                         ACHAR * szValue = NULL;                          int  buffSize = value.toString(NULL, 0);                         if  (buffSize > 0)                         {                                 buffSize++;                                 szValue = new  ACHAR[buffSize];                                 value.toString(szValue, buffSize);                         }                          strValue.format(                                 _T("%s = %s" ),                                 value.type().name(),                                  (szValue == NULL) ? _T("none" ) : szValue);                            if  (szValue)                                 delete  szValue;                 }                 else                 {                         strValue.format(_T("Error Code = %d" ), err);                 }         }          AcString str;         str.format(_T("\\n%s - %s [%s]" ), member->isA()->name(),                 member->name(), strValue.kACharPtr());         acutPrintf(str);          const  AcRxAttributeCollection & atts                 = member->attributes();                          for  (int  i = 0; i < atts.count(); i++)         {                 const  AcRxAttribute * att = atts.getAt(i);                   AcString attInfo;                 getAttInfo(att, member, attInfo);                  acutPrintf(attInfo);         }          if  (member->children() != NULL)         {                 for  (int  i = 0;                         i < member->children()->length(); i++)                 {                         const  AcRxMember * subMember                                 = member->children()->at(i);                         printValues(entity, subMember);                   }         } }

The CRX plugin exposes the "EntProps" command which requires handle of the entity for which the properties are to be retrieved as its input.
Here is a sample script file to load the crx and invoke "EntProps" command.
(arxload "D:\\Temp\\CrxTest1.crx")
EntProps
4C4   ;; Handle of the entity for which properties are to be displayed


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

本版积分规则

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

GMT+8, 2024-6-5 00:33 , Processed in 0.259302 second(s), 28 queries , Gzip On.

Powered by Discuz! X3.5

© 2001-2024 Discuz! Team.

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