设为首页收藏本站

晓东CAD家园-论坛

 找回密码
 立即注册

QQ登录

只需一步,快速开始

扫一扫,访问微社区

查看: 459|回复: 1

[每日一码] 获得属性块的所有属性值

[复制链接]

已领礼包: 1个

财富等级: 恭喜发财

发表于 2017-8-16 13:44:44 | 显示全部楼层 |阅读模式

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

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

x


  1. #include <dbobjptr.h>
  2. void PrintBlockAttributes()
  3. {
  4.   // get the current database
  5.   AcDbDatabase* pDb = acdbHostApplicationServices()->workingDatabase();
  6.   assert(pDb);

  7.   // in this sample we will only process block references in model space;
  8.   // it is also possible to have block references in paper space
  9.   // but I will leave it up to you to update the code to do so
  10.   AcDbBlockTableRecordPointer pModelSpace(ACDB_MODEL_SPACE, pDb, AcDb::kForRead);
  11.   assert(pModelSpace.openStatus() == Acad::eOk);

  12.   // request an iterator for the entities in the block table record
  13.   AcDbBlockTableRecordIterator *pIterator;
  14.   pModelSpace->newIterator(pIterator);

  15.   // iterate through each entity
  16.   for( ; !pIterator->done(); pIterator->step())
  17.   {
  18.     AcDbObjectId id;
  19.     pIterator->getEntityId(id);
  20.     // we are only interested in block references;
  21.     // ignore anything else
  22.     AcDbObjectPointer<AcDbBlockReference> pBlockReference(id, AcDb::kForRead);
  23.     if (pBlockReference.openStatus() != Acad::eOk)
  24.       continue;

  25.     // lets request the block reference for an attribute iterator
  26.     AcDbObjectIterator *pAttributeIterator = NULL;
  27.     pAttributeIterator = pBlockReference->attributeIterator();

  28.     // iterate through each attribute and print its value
  29.     for( ; !pAttributeIterator->done(); pAttributeIterator->step())
  30.     {
  31.       AcDbObjectId attributeId = pAttributeIterator->objectId();
  32.       // open the attribute
  33.       AcDbAttribute *pAttribute;
  34.       Acad::ErrorStatus es = pBlockReference->openAttribute(pAttribute, attributeId, AcDb::kForRead);
  35.       // finally; we are at a point where we have access tothe
  36.       // value of the attribute -- for now, simply display it

  37.       // AcDbAttribute is derived from AcDbText where the tag
  38.       // value is stored
  39.       ACHAR *pTag = pAttribute->tag();
  40.       assert(pTag != NULL);

  41.       ACHAR *pValue = pAttribute->textString();
  42.       assert(pValue != NULL);

  43.       // display
  44.       acutPrintf(L"Tag: %s = Value: %s\n", pTag, pValue);

  45.       // we no longer need this attribute so lets close it
  46.       // and clean up the memory
  47.       pAttribute->close();
  48.       delete [] pTag;
  49.       delete [] pValue;
  50.     }

  51.     // it is the programmer's responsibility to delete the
  52.     // attribute iterator
  53.     delete pAttributeIterator;
  54.   }

  55.   // it is the programmer's responsibility to delete the
  56.   // block table record iterator
  57.   delete pIterator;
  58. }



论坛插件加载方法
发帖求助前要善用【论坛搜索】功能,那里可能会有你要找的答案;
如果你在论坛求助问题,并且已经从坛友或者管理的回复中解决了问题,请把帖子标题加上【已解决】;
如何回报帮助你解决问题的坛友,一个好办法就是给对方加【D豆】,加分不会扣除自己的积分,做一个热心并受欢迎的人!
发表于 2019-12-16 21:03:53 | 显示全部楼层
感谢分享,学习一下先
论坛插件加载方法
发帖求助前要善用【论坛搜索】功能,那里可能会有你要找的答案;
如果你在论坛求助问题,并且已经从坛友或者管理的回复中解决了问题,请把帖子标题加上【已解决】;
如何回报帮助你解决问题的坛友,一个好办法就是给对方加【D豆】,加分不会扣除自己的积分,做一个热心并受欢迎的人!
回复 支持 反对

使用道具 举报

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

本版积分规则

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

GMT+8, 2021-1-28 04:06 , Processed in 0.132892 second(s), 21 queries , Gzip On, WinCache On.

Powered by Discuz! X3.4

Copyright © 2001-2020, Tencent Cloud.

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