hact 发表于 2007-1-8 16:32:00

[求助]怎么样一次性画多条直线,进来看看代码

<p>我想输入两个点的坐标之后出来两条直线,下面是画直线的代码,大家帮我看看</p><p>按照这段代码这样执行的话pLine是一个点,pLine2的直线倒能画出来,请问是怎么回事?</p><p>另ads_point,ads_name的定义哪里有得查啊?</p><p>谢谢</p><p>Acad::ErrorStatus<br/>postToDatabase(AcDbEntity* pEnt,AcDbObjectId&amp; idObj)<br/>{<br/>&nbsp;Acad::ErrorStatus es;<br/>&nbsp;AcDbBlockTable* pBlockTable;<br/>&nbsp;AcDbBlockTableRecord* pSpaceRecord;<br/>&nbsp;if(acdbHostApplicationServices()-&gt;workingDatabase()==NULL)<br/>&nbsp;&nbsp;return Acad::eNoDatabase;<br/>&nbsp;if ((es=acdbHostApplicationServices()-&gt;workingDatabase()-&gt;getBlockTable(pBlockTable,AcDb::kForRead))==Acad::eOk)<br/>&nbsp;{<br/>&nbsp;&nbsp;if((es=pBlockTable-&gt;getAt(ACDB_MODEL_SPACE,pSpaceRecord,AcDb::kForWrite))==Acad::eOk)<br/>&nbsp;&nbsp;{<br/>&nbsp;&nbsp;&nbsp;if((es=pSpaceRecord-&gt;appendAcDbEntity(idObj,pEnt))==Acad::eOk)<br/>&nbsp;&nbsp;&nbsp;&nbsp;pEnt-&gt;close();<br/>&nbsp;&nbsp;&nbsp;pSpaceRecord-&gt;close();<br/>&nbsp;&nbsp;}<br/>&nbsp;&nbsp;pBlockTable-&gt;close();<br/>&nbsp;}<br/>&nbsp;return es;<br/>}<br/>//-----------------以下开始添加直线------------------------------------<br/>Acad::ErrorStatus newLine()<br/>{<br/>&nbsp;ads_point pt1,pt2;<br/>&nbsp;ads_point pt3,pt4;<br/>&nbsp;int retval;<br/>&nbsp;try<br/>&nbsp;{<br/>&nbsp;&nbsp;if((retval=acedGetPoint(NULL, "\nSelect lower left:",pt1))!=RTNORM)<br/>&nbsp;&nbsp;&nbsp;throw retval;<br/>&nbsp;&nbsp;if((retval=acedGetPoint(pt1,"\nSelect upper right:",pt2))!=RTNORM)<br/>&nbsp;&nbsp;&nbsp;throw retval;<br/>&nbsp;}<br/>&nbsp;catch (int e)<br/>&nbsp;{<br/>&nbsp;&nbsp;if(e==RTCAN)<br/>&nbsp;&nbsp;&nbsp;return Acad::eUserBreak ;<br/>&nbsp;&nbsp;if(e==RTERROR)<br/>&nbsp;&nbsp;&nbsp;return Acad::eInvalidInput ;<br/>&nbsp;}<br/>&nbsp;pt3=pt1;<br/>&nbsp;pt3=pt1+10;<br/>&nbsp;pt3=pt1;<br/>&nbsp;pt4=pt1;<br/>&nbsp;pt4=pt1+10;<br/>&nbsp;pt4=pt1;<br/>&nbsp;AcDbLine* pLine =new AcDbLine(asPnt3d(pt1),asPnt3d(pt2));<br/>&nbsp;AcDbLine* pLine2 =new AcDbLine(asPnt3d(pt3),asPnt3d(pt4));<br/>&nbsp;if(!pLine || !pLine2)<br/>&nbsp;{<br/>&nbsp;&nbsp;acedAlert("Not enough memory to create a Line!");<br/>&nbsp;&nbsp;return Acad::eOutOfMemory ;<br/>&nbsp;}</p><p><br/>&nbsp;AcDbObjectId id;<br/>&nbsp;postToDatabase(pLine,id);<br/>&nbsp;return postToDatabase(pLine2,id);</p><p>}<br/></p>

hact 发表于 2007-1-8 17:21:00

<p>自己来坐沙发吧</p><p>pt3=pt1;<br/>&nbsp;pt3=pt1+10;<br/>&nbsp;pt3=pt1;<br/>&nbsp;pt4=pt1;<br/>&nbsp;pt4=pt1+10;<br/>&nbsp;pt4=pt1;<br/></p><p>晕死,这里写错了.应该为</p><p>pt3=pt1;<br/>&nbsp;pt3=pt1+10;<br/>&nbsp;pt3=pt1;<br/>&nbsp;pt4=pt2;<br/>&nbsp;pt4=pt2+10;<br/>&nbsp;pt4=pt2;<br/></p><p>大家还有更好的方法来实现这个多线么?</p>

hact 发表于 2007-1-8 17:21:00

<p>自己沙发了</p><p>pt3=pt1;<br/>&nbsp;pt3=pt1+10;<br/>&nbsp;pt3=pt1;<br/>&nbsp;pt4=pt1;<br/>&nbsp;pt4=pt1+10;<br/>&nbsp;pt4=pt1;<br/>错了,</p><p>应该为</p><p>pt3=pt1;<br/>&nbsp;pt3=pt1+10;<br/>&nbsp;pt3=pt1;<br/>&nbsp;pt4=pt2;<br/>&nbsp;pt4=pt2+10;<br/>&nbsp;pt4=pt2;<br/></p>

shinjikun 发表于 2007-1-13 10:59:00

既然你直接return不作处理,何必使用try/catch呢?

hact 发表于 2007-1-14 21:21:00

try/catch是捕捉选点的时候的throw阿
页: [1]
查看完整版本: [求助]怎么样一次性画多条直线,进来看看代码