本帖最后由 vectra 于 2014-12-21 08:23 编辑
求形心函数改自Z版,特此声明
同时修改了移位后重新计算形心,以保持以选择集中心旋转。
- (defun c:tt (/ _getreal _getpoint gr ss str)
- (defun _getreal (msg default / ret)
- (setq ret (getreal (strcat msg " <" (rtos default) ">:")))
- (if (null ret)
- default
- ret
- )
- )
- (defun _getpoint (ss / a b i m1 m2 p1 p2)
- (repeat (setq i (sslength ss))
- (vla-getboundingbox (vlax-ename->vla-object (ssname ss (setq i (1- i)))) 'p1 'p2)
- (setq p1 (vlax-safearray->list p1)
- p2 (vlax-safearray->list p2)
- )
- (if (null m1)
- (setq m1 p1)
- (setq m1 (mapcar 'min m1 p1))
- )
- (if (null m2)
- (setq m2 p2)
- (setq m2 (mapcar 'max m2 p2))
- )
- )
- (mapcar '(lambda (a b) (/ (+ a b) 2)) m1 m2)
- )
- (setvar 'cmdecho 0)
- (if (null *grmovedis*)
- (setq *grmovedis* 4.0)
- )
- (if (null *grangles*)
- (setq *grangles* 90.0)
- )
- (setq str "\n按W S A D 移动, Q向左旋转, E向右旋转 R设置步长 T设置角度, 空格回车或左\右键退出:")
- (princ (strcat "\n步长 = " (rtos *grmovedis* 2) ""))
- (if (setq ss (ssget))
- (progn (princ str)
- (while (and (/= (car (setq gr (grread t 15 0))) 3)
- (not (equal gr '(2 32)))
- (not (equal gr '(2 13)))
- (not (equal gr '(11 0)))
- (not (equal gr '(25 0)))
- )
- (cond ((or (equal gr '(2 119)) (equal gr '(2 87))) ;wW
- (vl-cmdf "_.move" ss "" '(0 0) (polar '(0 0) (* pi 0.5) *grmovedis*))
- )
- ((or (equal gr '(2 83)) (equal gr '(2 115))) ;Ss
- (vl-cmdf "_.move" ss "" '(0 0) (polar '(0 0) (* pi 1.5) *grmovedis*))
- )
- ((or (equal gr '(2 65)) (equal gr '(2 97))) ;Aa
- (vl-cmdf "_.move" ss "" '(0 0) (polar '(0 0) pi *grmovedis*))
- )
- ((or (equal gr '(2 68)) (equal gr '(2 100))) ;Dd
- (vl-cmdf "_.move" ss "" '(0 0) (polar '(0 0) 0 *grmovedis*))
- )
- ((or (equal gr '(2 69)) (equal gr '(2 101))) ;Ee
- (vl-cmdf "_.rotate" ss "" (_getpoint ss) (- *grangles*))
- )
- ((or (equal gr '(2 81)) (equal gr '(2 113))) ;Qq
- (vl-cmdf "_.rotate" ss "" (_getpoint ss) *grangles*)
- )
- ((or (equal gr '(2 82)) (equal gr '(2 114))) ;Rr
- (setq *grmovedis* (_getreal "\n输入每次移动的步长" *grmovedis*))
- (princ str)
- )
- ((or (equal gr '(2 84)) (equal gr '(2 116))) ;Tt
- (setq *grangles* (abs (_getreal "\n输入每次旋转的角度" *grangles*)))
- (princ str)
- )
- )
- )
- )
- )
- (setvar 'cmdecho 1)
- (princ)
- )
|