我在外部图纸中做了一个块,把它插入到当前图纸中,希望实现该块与直线相交获得焦点,删除旧直线,然后重画两条直线,实现"打断"功能.可是插入后却第一次插入后只能在块的最左边获得一个焦点,第二次以后就能实现预期的功能,这到底是什么原因啊?希望能由高手赐教!代码如下: //搜索数据库中所有的直线 AcDbObjectIdArray lineIdArray; AcGePoint3d pt1,pt2; AcDbBlockTableRecordIterator *pBlkItr; pCurDb->getSymbolTable(pBlockTable,AcDb::kForRead); pBlockTable->getAt(ACDB_MODEL_SPACE,pBlockTableRecord,AcDb::kForRead); pBlockTable->close(); pBlockTableRecord->newIterator(pBlkItr); pBlockTableRecord->close(); for(pBlkItr->start();!pBlkItr->done();pBlkItr->step()) { AcDbEntity* pEntity; AcDbObjectId lineId; pBlkItr->getEntity(pEntity,AcDb::kForRead); //acedAlert(pEntity->isA()->name()); //// /*if(!strcmp("_line",(pEntity->isA()->name()))) { lineId=pEntity->objectId(); lineIdArray.append(lineId); } pEntity->close();*/ //// //if(!strcmp("AcDbLine",(pEntity->isA()->name()))) if(pEntity->isKindOf(AcDbLine::desc())) { lineId=pEntity->objectId(); lineIdArray.append(lineId); } pEntity->close(); } delete pBlkItr; int nLineNumber=lineIdArray.length(); AcDbEntity* pBlock; acdbOpenObject(pBlock,refId,AcDb::kForRead); for(int i=0;i<nLineNumber;i++) { AcDbLine* pLine; AcDbObjectId id=lineIdArray.at(i); AcGePoint3dArray pts; acdbOpenObject(pLine,id,AcDb::kForWrite); pBlock->boundingBoxIntersectWith(pLine,AcDb::kOnBothOperands,pts,0,0); //pLine->intersectWith(pBlock,AcDb::kOnBothOperands,pts); //AcGePoint3d pt1=points.first(); //AcGePoint3d pt2=points.last(); //AcGePoint2d pot1(pt1.x,pt1.y); //AcGePoint2d pot2(pt2.x,pt2.y); /*if (pts.length()==0)//直线与块没有交点 { pLine->close(); continue; }*/ //pts. if(pts.length()>0) { double dis1 = pts.first().distanceTo(pLine->startPoint()); double dis2 = pts.last().distanceTo(pLine->startPoint()); acutPrintf("\nthe length is %0.6f",pts.length()); //pts. //acutPrintf("the length is %0.6f",dis2); if (dis1 > dis2 ) { pt1 = pts.last(); pt2 = pts.first(); } else { acutPrintf("\nthe length of two point is Longer than 12"); pt1 = pts.first(); pt2 = pts.last(); } AcDbLine* line1=new AcDbLine(pLine->startPoint(), pt1); AcDbLine* line2=new AcDbLine(pt2, pLine->endPoint()); pLine->erase();
pCurDb->getSymbolTable(pBlockTable,AcDb::kForRead); pBlockTable->getAt(ACDB_MODEL_SPACE,pBlockTableRecord,AcDb::kForWrite); pBlockTable->close(); AcDbObjectId lineId1,lineId2; pBlockTableRecord->appendAcDbEntity(lineId1,line1); pBlockTableRecord->appendAcDbEntity(lineId2,line2); line1->close(); line2->close(); pBlockTableRecord->close(); //continue; } pLine->close(); } pBlock->close(); //pBlockTableRecord->close(); acDocManager->unlockDocument(curDoc());
|