Resetting the origins of block table records in a drawing
Issue
I have a drawing that contains block table records with non-zero origins, i.e.
they are not set to (0, 0, 0). How can I reset these origins without moving the
positions of all the block‘s sub-entities in the drawing?
Solution
The following code demonstrates how to modify a block table record‘s
origin and compensate by moving the insertion point of each of the associated
block references.
Please add the function ‘testFunc‘ as a command.
[code=cpp]
void ResetAllInstances(AcDbBlockTableRecord * pBlockTableRecord, AcGeVector3d &translation)
{
// Note that this function does not implement any error checking.
// We are assuming that pBlockTableREcord was opened for write by the calling function
// Iterate through all block references of this block table record.
AcDbBlockReferenceIdIterator * pIterator;
pBlockTableRecord->newBlockReferenceIdIterator(pIterator);
for (pIterator->start();!pIterator->done();pIterator->step())
{
AcDbBlockReference * pBlockRef;
pIterator->getBlockReference(pBlockRef, AcDb::kForWrite,true);
// Transform the translation vector from block coordinates to world coordinates.
AcGeVector3d realTranslation = (pBlockRef->blockTransform())*translation;
// Translate the block reference to counter the effect of the origin change.
pBlockRef->setPosition(pBlockRef->position()+realTranslation);
pBlockRef->close();
} // Next block reference
delete pIterator;
}
[/code]
下面是测试命令SGP
原文:https://www.cnblogs.com/mjgw/p/12459539.html