找回密码
 立即注册

QQ登录

只需一步,快速开始

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

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

[复制链接]

1

主题

0

回帖

33

积分

管理员

积分
33
发表于 2024-3-14 20:50:22 | 显示全部楼层 |阅读模式
  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. }
复制代码
您需要登录后才可以回帖 登录 | 立即注册

本版积分规则

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

GMT+8, 2024-12-29 21:44 , Processed in 0.138590 second(s), 21 queries .

Powered by Discuz! X3.5

© 2001-2024 Discuz! Team.

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