⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 选择集中点lisp.lsp

📁 选择集中点LISP,非常经典
💻 LSP
字号:
(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
  )
)

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -