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