- 积分
- 469
- 明经币
- 个
- 注册时间
- 2004-7-13
- 在线时间
- 小时
- 威望
-
- 金钱
- 个
- 贡献
-
- 激情
-
|
本人用arx编写了一个计算所选取直线总长度的程序,感觉挺不方便,大家给点意见。
void GetSelLens() { ads_name ent1,ssents; long i(0),n; char* entname; struct resbuf *rb,*rbtmp; double fLength(0); AcGePoint3d *pt1,*pt2;
acedSSGet(NULL,NULL,NULL,NULL,ssents); acedSSLength(ssents,&n); for (;i<n;i++) { acedSSName(ssents,i,ent1); rb=acdbEntGet(ent1); for (rbtmp=rb;rbtmp!=NULL;rbtmp=rbtmp->rbnext) { if (rbtmp->restype==0) { entname=rbtmp->resval.rstring; continue; } if (rbtmp->restype==10) pt1=new AcGePoint3d(rbtmp->resval.rpoint[X],rbtmp->resval.rpoint[Y], rbtmp->resval.rpoint[Z]); if (rbtmp->restype==11) pt2=new AcGePoint3d(rbtmp->resval.rpoint[X],rbtmp->resval.rpoint[Y], rbtmp->resval.rpoint[Z]); } if (!strcmp(entname,"LINE")) { fLength+=GetLineLen(pt1,pt2); } }
acutPrintf("总长度 %f",fLength); // return 0; }
double GetLineLen(AcGePoint3d *pt1,AcGePoint3d *pt2) { double len=sqrt(pow(pt1->x-pt2->x,2)+pow(pt1->y-pt2->y,2)+pow(pt1->z-pt2->z,2)); return len; }
有人用vlisp编写了计算弧线和直线总长的程序,很简单。
(defun C:calEN (/ CURVE TLEN SS N SUMLEN) (vl-load-com) (setq SUMLEN 0) (setq SS (ssget '((0 . "CIRCLE,ELLIPSE,LINE,*POLYLINE,SPLINE,ARC")))) (setq N 0) (repeat (sslength SS) (setq CURVE (vlax-ename->vla-object (ssname SS N))) (setq TLEN (vlax-curve-getdistatparam CURVE (vlax-curve-getendparam CURVE) ) ) (setq SUMLEN (+ SUMLEN TLEN)) (setq N (1+ N)) ) (print (strcat "总长度: " (rtos SUMLEN 2 5))) (princ) ) |
|