乐筑天下

搜索
欢迎各位开发者和用户入驻本平台 尊重版权,从我做起,拒绝盗版,拒绝倒卖 签到、发布资源、邀请好友注册,可以获得银币 请注意保管好自己的密码,避免账户资金被盗
查看: 31|回复: 1

[求助]如何获取用insert插入的属性块的各属性值(块名已知)

[复制链接]

3

主题

3

帖子

2

银币

初来乍到

Rank: 1

铜币
15
发表于 2005-8-22 10:09:00 | 显示全部楼层 |阅读模式
如何获取用insert插入的属性块的各属性值(块名已知)
回复

使用道具 举报

11

主题

33

帖子

3

银币

初露锋芒

Rank: 3Rank: 3Rank: 3

铜币
77
发表于 2005-8-22 10:47:00 | 显示全部楼层
这是一本书中的例子,每一行代码的例子我还不太懂,你自己看看吧.其中包括插入块的代码.
void insrtBlk()
{
char blkName[50];
AcDbDatabase *pCurDb;
AcDbBlockTable *pBlkTable;
AcDbBlockTableRecord *pBlkTableRecord;
AcDbBlockTableRecord *pBlkDefRecord;
AcDbBlockReference *pInsrtObj;
AcDbEntity *pEnt;
AcDbBlockTableRecordIterator *pIterator;
AcDbAttributeDefinition *pAttDef;
AcDbAttribute *pAtt;
AcDbObjectId blkId;
AcDbObjectId insrtId;
char *pTagPrompt;
AcGePoint3d insPt;
AcGePoint3d basePt;
int retCode;
retCode = acedGetString(0, "\nEnter Block Name: ", blkName);
if(retCode != RTNORM || blkName[0] == '\0')
{
  acutPrintf("\nInvalid block name.");
  return;
}
pCurDb = acdbHostApplicationServices()->workingDatabase();
// Check to see if the block table
// has blkName
pCurDb->getBlockTable(pBlkTable, AcDb::kForRead);
if(!pBlkTable->has(blkName))
{
  acutPrintf("\nBlock definition %s not found. ", blkName);
  pBlkTable->close();
  return;
}
// Get the AcDbObjectId of the block
// definition.
pBlkTable->getAt(blkName, blkId);
pBlkTable->getAt(ACDB_MODEL_SPACE, pBlkTableRecord, AcDb::kForWrite);
pBlkTable->close();

acedInitGet(RSG_NONULL, NULL);
acedGetPoint(NULL, "\nPick insertion point: ", asDblArray(insPt));
pInsrtObj = new AcDbBlockReference(insPt, blkId);
// Here is where you can set scale, rotation and other
// properties to the block entity. If you want to
// see the AcDbBlockReference class for more details.
pBlkTableRecord->appendAcDbEntity(insrtId, pInsrtObj);

acdbOpenObject(pBlkDefRecord, blkId, AcDb::kForRead);
// Now check to see if the Block Definition
// has attributes. If it does we will add
// a Block Table Record Iterator to step through
// the entities and find the Attribute Definitions.
if(pBlkDefRecord->hasAttributeDefinitions())
{
  pBlkDefRecord->newIterator(pIterator);
  for(pIterator->start(); !pIterator->done(); pIterator->step())
  {
   pIterator->getEntity(pEnt, AcDb::kForRead);
   // Check to see if the entity is an
   // attribute definition.
   pAttDef = AcDbAttributeDefinition::cast(pEnt);
   if(pAttDef != NULL && !pAttDef->isConstant())
   {
    // If it is and its not constant
    // create a new attribute
    pAtt = new AcDbAttribute();
    // setPropertiesFrom will copy
    // Color, Layer, Linetype,Linetype scale and
    // Visibility.
    pAtt->setPropertiesFrom(pAttDef);
    // setup more properties from the attribute
    // definition
    pAtt->setInvisible(pAttDef->isInvisible());
    basePt = pAttDef->position();
    basePt += pInsrtObj->position().asVector();
    pAtt->setPosition(basePt);
    pAtt->setHeight(pAttDef->height());
    pAtt->setRotation(pAttDef->rotation());
    // Take note how we get the tag.
    pTagPrompt = pAttDef->tag();
    pAtt->setTag(pTagPrompt);
    free(pTagPrompt);
    // Normally you would prompt the user
    // and ask for input values.
    pTagPrompt = pAttDef->prompt();
    acutPrintf("%s%s", "\n", pTagPrompt);
    free(pTagPrompt);
   
    // The setFieldLength is not required
    // even though it is listed in the
    // documentation.
    pAtt->setFieldLength(25);
    // setTextString is the value the
    // attribute receives which would
    // normally be a user input value.
    pAtt->setTextString("This is a test");
    pInsrtObj->appendAttribute(pAtt);
    pAtt->close();
   }
   pEnt->close();
  }// for
  delete pIterator;
}// if has attribute definitions
  // Note that we close the Model Space
// block table record after we have added
// our attributes.
pBlkTableRecord->close();
pInsrtObj->close();
}
回复

使用道具 举报

发表回复

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

本版积分规则

  • 微信公众平台

  • 扫描访问手机版

  • 点击图片下载手机App

QQ|关于我们|小黑屋|乐筑天下 繁体中文

GMT+8, 2025-2-5 13:51 , Processed in 0.196345 second(s), 56 queries .

© 2020-2025 乐筑天下

联系客服 关注微信 帮助中心 下载APP 返回顶部 返回列表