<P>(Defun C:test (/ ss)<BR> (VL-LOAD-COM)<BR> ;; get the selection set .<BR> (princ "\nPlease select object:")<BR> (setq ss (vl-catch-all-apply 'ssget))<BR> (if (or (vl-catch-all-error-p ss) (null ss))<BR> (vl-exit-with-value 0)<BR> )<BR> ;; get the Middle point from the selection set .<BR> (setq pt (GetMidPt ss))<BR> (if pt<BR> (foreach n (list "\nThe Middle Point X=" (car pt) " Y=" (cadr pt)) (princ n))<BR> (princ "\n There is error , can't get the middle point...")<BR> )<BR> (prin1)<BR>)<BR>;; the sub function to get the middle point from the selection set .<BR>(defun GetMidPt (ss / i lstX lstY vn pt X1 X2 Y1 Y2)</P>
<P> (setq i 0<BR> lstX '()<BR> lstY '()<BR> )<BR> (repeat (sslength ss)<BR> (setq vn (vlax-ename->vla-object (ssname ss i))<BR> i (1+ i)<BR> )<BR> (setq pt (vl-catch-all-apply 'vla-getBoundingBox (list vn 'MinPt 'MaxPt)))<BR> (if (not (vl-catch-all-error-p pt))<BR> (progn<BR> (setq X1 (vlax-safeArray-get-element MinPt 0)<BR> X2 (vlax-safeArray-get-element MaxPt 0)<BR> Y1 (vlax-safeArray-get-element MinPt 1)<BR> Y2 (vlax-safeArray-get-element MaxPt 1)<BR> )<BR> (cond<BR> ;; if this is the first time run,then put the value it .<BR> ((null lstX)<BR> (setq lstX (list X1 X2)<BR> lstY (list Y1 Y2)<BR> )<BR> )<BR> ;; NOTE here, .<BR> (T<BR> ;; X-Min .<BR> (if (< X1 (car lstX))<BR> (setq lstX (list X1 (cadr lstX)))<BR> )<BR> ;; X-Max<BR> (if (> X2 (cadr lstX))<BR> (setq lstX (list (car lstX) X2))<BR> )<BR> ;; Y-Min .<BR> (if (< Y1 (car lstY))<BR> (setq lstY (list Y1 (cadr lstY)))<BR> )<BR> ;; Y-Max<BR> (if (> Y2 (cadr lstY))<BR> (setq lstY (list (car lstY) Y2))<BR> )<BR> )<BR> )<BR> )<BR> )<BR> )<BR> ;; return the point .<BR> (if lstX<BR> (list (* (apply '+ lstX) 0.5) (* (apply '+ lstY) 0.5))<BR> nil<BR> )<BR>)</P> <P>还是楼上的好!学习!</P> 来看看,好像不难得
页:
1
[2]