|
- 以下代码通过选择一个块参照,将块内的圆对象的坐标转换为该圆在当前dwg中的坐标并输出。相当于炸开块参照后再读取圆对象坐标的效果
- ads采用name ObjName;
- ads采用point pnt;
- AcDbObjectId objId;
- if (RTNORM != acedEntSel(采用T(""),ObjName,pnt))
- {
- return;
- }
-
- acdbGetObjectId(objId,ObjName);
- AcDbEntity *pEnt=NULL;
- acdbOpenObject(pEnt,objId,AcDb::kForRead);
- if(pEnt->isKindOf(AcDbBlockReference::desc()))
- {
- AcDbBlockReference *pBlkRef=AcDbBlockReference::cast(pEnt);
- AcGeMatrix3d mat= pBlkRef->blockTransform();
-
- AcDbBlockTableRecordPointer BlkTBRec采用Ptr(pBlkRef->blockTableRecord(),AcDb::kForRead);
- if(Acad::eOk == BlkTBRec采用Ptr.openStatus())
- {
- AcDbBlockTableRecordIterator *pIt=NULL;
- BlkTBRec采用Ptr->newIterator(pIt);
- for (pIt->start();!pIt->done();pIt->step())
- {
- AcDbEntity *pEntItem=NULL;
- pIt->getEntity(pEntItem,AcDb::kForRead);
- if(pEntItem->isKindOf(AcDbCircle::desc()))
- {
- AcDbCircle *pCircle=AcDbCircle::cast(pEntItem);
- AcGePoint3d transPnt= mat * pCircle->center(); //将变换矩阵应用到对象的块内位置上,即得其在当前dwg图中的位置
- acutPrintf(采用T("块内位置:%f,%f\n"),pCircle->center().x,pCircle->center().y);
- acutPrintf(采用T("在当前图中的位置%f,%f\n"),transPnt.x,transPnt.y);
- }
- pEntItem->close();
- }
- delete pIt;
- }
- }
- pEnt->close();
复制代码 |
|