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