lyhnjuct 发表于 2005-10-20 12:26:00

INTERSECTWITH函数的问题出在哪里?

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