AcDbBlockReference::openAttribute Function?

AcDbBlockReference::openAttribute Function?

Anonymous
Not applicable
415 Views
1 Reply
Message 1 of 2

AcDbBlockReference::openAttribute Function?

Anonymous
Not applicable
Has anyone use this function
Could some one send me a sample code of this just to get an Idea of how to
use it

A little more then this
Acad::ErrorStatus

openAttribute(

AcDbAttribute*& unnamed,

AcDbObjectId unnamed,

AcDb::OpenMode unnamed,

bool openErasedOne = false);



thanks in advance
0 Likes
416 Views
1 Reply
Reply (1)
Message 2 of 2

Anonymous
Not applicable
The functions below use it to get attribute values into a CStringList. The
first one asks you to select a block and then find its attributes by calling
the second one.

I hope it helps,

Vinicius



void pickBlock(CStringList& strList)
{
ads_name en;
ads_point pt;

if(ads_entsel("Select a block insert:", en, pt) != RTNORM)
{
ads_printf("\nError selecting entity.");
return;
}

AcDbObjectId objId;
if (acdbGetObjectId(objId, en) != Acad::eOk)
{
ads_printf("Error retrieving object id.\n");
return;
}

AcDbObject *pObj;
if ((acdbOpenObject(pObj, objId, AcDb::kForRead)) != Acad::eOk)
{
ads_printf("Error opening entity for read.\n");
return;
}

AcDbBlockReference* pBlk;
if(pObj->isKindOf(AcDbBlockReference::desc()))
{
pBlk = AcDbBlockReference::cast(pObj);
assert(pBlk);
if(!pBlk)
{
pObj->close();
return;
}
}
else
{
ads_printf("\nEntity selected is not a block");
pObj->close();
return;
}

ads_printf("\n");
getAttributeValues(pBlk, strList);

pBlk->close();

return;
}


Acad::ErrorStatus getAttributeValues(AcDbBlockReference*& pObj, CStringList&
strList)
{
// Acad::ErrorStatus es;
AcDbObjectIterator *pIter = NULL;
pIter = pObj->attributeIterator();
assert(pIter);

for(pIter->start(); !pIter->done(); pIter->step())
{
AcDbAttribute* pAttrib;
AcDbObjectId attId = pIter->objectId();

if (pObj->openAttribute(pAttrib, attId, AcDb::kForRead) == Acad::eOk)
{
CString str = pAttrib->textString();
if(str != "")
strList.AddTail(str);
pAttrib->close();
}
}
delete pIter;
return Acad::eOk;
}
0 Likes