AcDbAttribute::setPosition() 似乎有问题,如何解决?
AcDbAttribute::setPosition() function doesn't seem to function properly问题:
I use following codes to set attribute postion
pAttdef->setHorizontalMode(AcDb::kTextCenter);
pAttdef->setVerticalMode(AcDb::kTextVertMid);
pAttdef->setAlignmentPoint(basePoint);
However the attribute text shows on origin st the beginning. when I move the blockreference a little bit the attrbute text comes back to the block center.
解答:
I understand what kind of problem that you're having. It has something to do
with the order of setting the AcDbAttribute members.
It is to my knowledge that you must use setAlignmentPoint() function AFTER
setPosition(), setHorizontalMode() and setVerticalMode() functions because the
alignmentPoint is relative to the other settings.
The following code snippet demonstrated how it works in that order.
void testAttributeAlignment()
{
AcDbEntity* pEnt = NULL;
if(!getBlockReference(pEnt))
//my own function to a pointer to an entity
return;
AcDbBlockReference *pBlkRef = AcDbBlockReference::cast(pEnt);
AcDbAttribute *pAtt = NULL;
AcDbObjectIterator *pAttIter = pBlkRef->attributeIterator();
for (pAttIter->start(); !pAttIter->done(); pAttIter->step())
{
acdbOpenObject(pAtt, pAttIter->objectId(), AcDb::kForWrite);
pAtt->setHorizontalMode(AcDb::kTextCenter);
pAtt->setVerticalMode(AcDb::kTextVertMid);
AcGePoint3d insertPt = pAtt->position();
AcGePoint3d alignPt = pAtt->alignmentPoint();
if(insertPt != alignPt)
pAtt->setAlignmentPoint(insertPt);
pAtt->close();
}
delete pAttIter;
pBlkRef->close();
}
页:
[1]