[每日一码] AcDbBlockReference appendAttribute
static void AddAttrib(){
ads采用name ent;
ads采用point pt;
if (acedEntSel(采用T("\nPick Insert: "),ent,pt)==RTNORM)
{
AcDbObjectId objId,blkId;
acdbGetObjectId(objId,ent);
AcDbObjectPointer<AcDbBlockReference> pBlkRef(objId,AcDb::kForRead);
if (pBlkRef.openStatus()==Acad::eOk)
{
ACHAR tagstr,str;
if (acedGetString(NULL,采用T("\nTag String: "),tagstr)!=RTNORM)
{
return;
}
AcDbObjectIterator *pIter=pBlkRef->attributeIterator();
if (pIter!=NULL)
{
for (;!pIter->done();pIter->step())
{
AcDbObjectPointer<AcDbAttribute> pAttrib(pIter->objectId(),AcDb::kForRead);
if (采用tcscmp(pAttrib->tag(),tagstr)==0)
{
delete pIter;
acutPrintf(采用T("\n%s already exists!"),tagstr);
return;
}
}
delete pIter;
}
if (acedGetString(NULL,采用T("\nText String: "),str)!=RTNORM)
{
return;
}
if (acedGetPoint(NULL,采用T("\nInsertion Point: "),pt)!=RTNORM)
{
return;
}
pBlkRef->upgradeOpen();
AcDbAttribute *pAttrib=new AcDbAttribute;
pAttrib->setTag(tagstr);
pAttrib->setTextString(str);
pAttrib->setPosition(asPnt3d(pt));
pAttrib->setHeight(10.0);
pBlkRef->appendAttribute(pAttrib);
pAttrib->close();
pBlkRef->close();
}
}
}
页:
[1]