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