[ARX]如何闭合正在画的n边形?(给出源程序)
本帖最后由 作者 于 2005-9-29 10:05:51 编辑 <br /><br /> <P>附上我的测试程序,里面提供了我尺寸标注 求面积 画表格的程序</P><P>#include <aced.h><BR>#include <acedads.h><BR>#include <dbents.h><BR>#include <dbsymtb.h><BR>#include <dbgroup.h><BR>#include <dbapserv.h><BR>#include <acestext.h><BR>#include <migrtion.h><BR>#include <geassign.h><BR>#include <math.h><BR>#include <dbpl.h ></P>
<P> ads_point pt1;<BR> AcGePoint3d pt;<BR> int NodeNumCount; <BR>void area()<BR>{ <BR> int i=0;<BR> acedGetPoint(NULL,"\n请选择起始点:",asDblArray(pt));<BR> <BR> do {<BR> acedGetPoint(asDblArray(pt),"\n拾取下一点:",asDblArray(pt));<BR> AcDbLine *pLine=new AcDbLine(pt,pt);<BR> AcDbBlockTable *pBlkTable2;<BR> acdbHostApplicationServices()->workingDatabase()<BR> ->getSymbolTable(pBlkTable2, AcDb::kForRead);<BR> AcDbBlockTableRecord *pBlockTableRecord;<BR> <BR> pBlkTable2->getAt(ACDB_MODEL_SPACE, pBlockTableRecord,<BR> AcDb::kForWrite);<BR> pBlkTable2->close();<BR> <BR> AcDbObjectId lineId=AcDbObjectId::kNull;<BR> pBlockTableRecord->appendAcDbEntity(lineId, pLine);<BR> pBlockTableRecord->close();<BR> pLine->close();<BR> changepoint(pt1,pt);//转换点的类型<BR> changepoint(pt1,pt);//转换点的类型<BR> i++;<BR> NodeNumCount=i;//取得边数<BR> }<BR> while((Equal_Points (pt1, pt1))==0);//起始点=终点时结束循环<BR>}</P>
<P>int Equal_Points (const ads_point p1, const ads_point p2) //判断两点是否为同一点<BR>{<BR> // 指定误差范围<BR> const ads_real Equality_Margin = (ads_real)0.0001; <BR> int c ;<BR> for (c = X ; c <= Z ; c++) <BR> {<BR> if (fabs(p1 - p2) > Equality_Margin)<BR> { return (0) ; }<BR> }<BR> {<BR> AcDbLine *pLine=new AcDbLine(pt,pt);<BR> AcDbBlockTable *pBlkTable2;<BR> acdbHostApplicationServices()->workingDatabase()<BR> ->getSymbolTable(pBlkTable2, AcDb::kForRead);<BR> <BR> AcDbBlockTableRecord *pBlockTableRecord;<BR> <BR> pBlkTable2->getAt(ACDB_MODEL_SPACE, pBlockTableRecord,<BR> AcDb::kForWrite);<BR> pBlkTable2->close();<BR> <BR> AcDbObjectId lineId=AcDbObjectId::kNull;<BR> pBlockTableRecord->appendAcDbEntity(lineId, pLine);<BR> pBlockTableRecord->close();<BR> pLine->close();<BR> return (1) ;<BR> }<BR>}</P>
<P>void changepoint(ads_point& ads_pt,AcGePoint3d acge_pt) //AcGePoint3d转换成ads_point类型<BR>{ <BR> double x=acge_pt; <BR> double y=acge_pt; <BR> double z=acge_pt;<BR> ads_pt=x; <BR> ads_pt=y; <BR> ads_pt=z; <BR>}</P>
<P>对于如上这段画n边形的程序,有个失误的地方,就是他是以起点=终点来判断n边形画结束的,如果遇到图形线段很多时,如果找不到起点,就会陷入死循环!!</P>
<P>在正常的CAd画图中我们可以用“C”命令来闭合当前正在画的图形,请问这在程序中如何实现,希望有高手指点一下!</P> 斑竹能不能给个意见啊谢谢了 <P>你可以用AcDbPolyline来画多边形,然后调用setClosed(Adesk::kTrue)实现闭合</P>
页:
[1]