ads_name ents; if(ads_ssget(NULL,NULL,NULL,NULL,ents) == RTNORM) { AcDbExtents ext; long nLen = 0; ads_sslength(ents,&nLen); long i = 0; for (; i < nLen; i++) { ads_name curEnt; ads_ssname(ents,i,curEnt); AcDbObjectId curId; if(acdbGetObjectId(curId,curEnt) != Acad::eOk) continue; AcDbEntity * pEnt = NULL; acdbOpenAcDbEntity(pEnt,curId,AcDb::kForRead); if (pEnt == NULL) continue; AcDbExtents curExt; pEnt->getGeomExtents(curExt); ext.addExt(curExt); } ads_ssfree(ents); AcDbDatabase * pDb = acdbCurDwg(); if (pDb == NULL) return; AcDbBlockTable * pBlock = NULL; pDb->getBlockTable(pBlock,AcDb::kForWrite); if (pBlock == NULL) return; AcDbBlockTableRecord * pRecord = NULL; pBlock->getAt(ACDB_MODEL_SPACE,pRecord,AcDb::kForWrite); if (pRecord == NULL) { pBlock->close(); return; } pBlock->close(); //绘制矩形 AcDbPolyline *pPolyExt = new AcDbPolyline; pPolyExt->addVertexAt(0,AcGePoint2d(ext.minPoint().x,ext.minPoint().y)); pPolyExt->addVertexAt(1,AcGePoint2d(ext.minPoint().x,ext.maxPoint().y)); pPolyExt->addVertexAt(2,AcGePoint2d(ext.maxPoint().x,ext.maxPoint().y)); pPolyExt->addVertexAt(3,AcGePoint2d(ext.maxPoint().x,ext.minPoint().y)); pPolyExt->setClosed(Adesk::kTrue); //绘制中心线 AcDbLine * pVLn = new AcDbLine,* pHLn = new AcDbLine; pVLn->setStartPoint(AcGePoint3d((ext.minPoint().x+ext.maxPoint().x)*0.5,ext.minPoint().y,0)); pVLn->setEndPoint(AcGePoint3d((ext.minPoint().x+ext.maxPoint().x)*0.5,ext.maxPoint().y,0)); pHLn->setStartPoint(AcGePoint3d(ext.minPoint().x,(ext.minPoint().y+ext.maxPoint().y)*0.5,0)); pHLn->setEndPoint(AcGePoint3d(ext.maxPoint().x,(ext.minPoint().y+ext.maxPoint().y)*0.5,0)); pRecord->appendAcDbEntity(pPolyExt); pRecord->appendAcDbEntity(pVLn); pRecord->appendAcDbEntity(pHLn); pPolyExt->close(); pVLn->close(); pHLn->close(); pRecord->close(); } |