明经CAD社区

 找回密码
 注册

QQ登录

只需一步,快速开始

搜索
12
返回列表 发新帖
楼主: caoyin

[求助]怎样获得选择集的中心点

  [复制链接]
发表于 2006-6-25 19:25 | 显示全部楼层

请看看这个,写得有点繁琐,不过还算是完成了...

(Defun C:test (/ ss)
  (VL-LOAD-COM)
  ;; get the selection set    .
  (princ "\nPlease select object:")
  (setq ss (vl-catch-all-apply 'ssget))
  (if (or (vl-catch-all-error-p ss) (null ss))
    (vl-exit-with-value 0)
  )
  ;; get the Middle point from the selection set .
  (setq pt (GetMidPt ss))
  (if pt
    (foreach n (list "\nThe Middle Point X=" (car pt) "  Y=" (cadr pt)) (princ n))
    (princ "\n There is error , can't get the middle point...")
  )
  (prin1)
)
;; the sub function to get the middle point from the selection set  .
(defun GetMidPt (ss / i lstX lstY vn pt X1 X2 Y1 Y2)

  (setq i    0
 lstX '()
 lstY '()
  )
  (repeat (sslength ss)
    (setq vn (vlax-ename->vla-object (ssname ss i))
   i  (1+ i)
    )
    (setq pt (vl-catch-all-apply 'vla-getBoundingBox (list vn 'MinPt 'MaxPt)))
    (if (not (vl-catch-all-error-p pt))
      (progn
 (setq X1 (vlax-safeArray-get-element MinPt 0)
       X2 (vlax-safeArray-get-element MaxPt 0)
       Y1 (vlax-safeArray-get-element MinPt 1)
       Y2 (vlax-safeArray-get-element MaxPt 1)
 )
 (cond
   ;; if this is the first time run,then put the value it .
   ((null lstX)
    (setq lstX (list X1 X2)
   lstY (list Y1 Y2)
    )
   )
   ;; NOTE here,  .
   (T
    ;; X-Min .
    (if (< X1 (car lstX))
      (setq lstX (list X1 (cadr lstX)))
    )
    ;; X-Max
    (if (> X2 (cadr lstX))
      (setq lstX (list (car lstX) X2))
    )
    ;; Y-Min .
    (if (< Y1 (car lstY))
      (setq lstY (list Y1 (cadr lstY)))
    )
    ;; Y-Max
    (if (> Y2 (cadr lstY))
      (setq lstY (list (car lstY) Y2))
    )
   )
 )
      )
    )
  )
  ;; return the point  .
  (if lstX
    (list (* (apply '+ lstX) 0.5) (* (apply '+ lstY) 0.5))
    nil
  )
)

 楼主| 发表于 2006-6-27 10:59 | 显示全部楼层

还是楼上的好!学习!

发表于 2009-2-3 15:27 | 显示全部楼层
来看看,好像不难得
您需要登录后才可以回帖 登录 | 注册

本版积分规则

小黑屋|手机版|CAD论坛|CAD教程|CAD下载|联系我们|关于明经|明经通道 ( 粤ICP备05003914号 )  
©2000-2023 明经通道 版权所有 本站代码,在未取得本站及作者授权的情况下,不得用于商业用途

GMT+8, 2024-5-1 00:43 , Processed in 0.184829 second(s), 19 queries , Gzip On.

Powered by Discuz! X3.4

Copyright © 2001-2021, Tencent Cloud.

快速回复 返回顶部 返回列表