本帖最后由 Gu_xl 于 2018-6-19 11:52 编辑
- ;;动态框绘制 By 明经通道 Gu_xl
- (defun c:DynRect (/ GR GetScreenCoords
- LL LMTS LOOP LU P1
- P2 P3 P4 PT RL
- RU S1 S2 S3 S4
- )
- ;;取得当前绘图区屏幕的左下角和右上角的坐标
- (defun GetScreenCoords
- (/ c03 c08 c04 c05 c07 c06 c09 c01 c02)
- (setq c03 (getvar "viewctr")
- c03 (trans c03 1 2)
- c08 (getvar "viewsize")
- c04 (getvar "screensize")
- c07 (car c04)
- c06 (cadr c04)
- c09 (/ (* c08 c07) c06)
- c01 (list (- (car c03) (* 0.5 c09)) (- (cadr c03) (* 0.5 c08)))
- c02 (list (+ (car c03) (* 0.5 c09)) (+ (cadr c03) (* 0.5 c08)))
- c01 (trans c01 2 1)
- c02 (trans c02 2 1)
- )
- (list c01 c02)
- )
- (setq loop t)
- (while loop
- (setq lmts (GetScreenCoords))
- (setq gr (grread t 15 0))
- (cond ((= 5 (car gr))
- (setq pt (cadr gr))
- (if (and
- (setq s1 (ssget "F"
- (list pt (list (car pt) (cadadr lmts) 0))
- '((0 . "*line,arc,circle"))
- )
- ) ;_ 向上
- (setq s2 (ssget "F"
- (list pt (list (car pt) (cadar lmts) 0))
- '((0 . "*line,arc,circle"))
- )
- ) ;_ 向下
- (setq s3 (ssget "F"
- (list pt (list (caar lmts) (cadr pt) 0))
- '((0 . "*line,arc,circle"))
- )
- ) ;_ 向左
- (setq s4 (ssget "F"
- (list pt (list (caadr lmts) (cadr pt) 0))
- '((0 . "*line,arc,circle"))
- )
- ) ;_ 向右
- )
- (progn
- (setq p1 (trans (cadar (cdddar (ssnamex s1))) 0 1)) ;_ 上点
- (setq p2 (trans (cadar (cdddar (ssnamex s2))) 0 1)) ;_ 下点
- (setq p3 (trans (cadar (cdddar (ssnamex s3))) 0 1)) ;_ 左点
- (setq p4 (trans (cadar (cdddar (ssnamex s4))) 0 1)) ;_ 右点
- (setq ll (apply 'mapcar (cons 'min (list p1 p2 p3 p4)))) ;_ 左下角点
- (setq ru (apply 'mapcar (cons 'max (list p1 p2 p3 p4)))) ;_ 右上角点
- (setq lu (list (car ll) (cadr ru) 0)) ;_ 左上角点
- (setq rl (list (car ru) (cadr ll) 0)) ;_ 右下角点
- (redraw)
- (grdraw ll lu 1)
- (grdraw lu ru 1)
- (grdraw ru rl 1)
- (grdraw rl ll 1)
- )
- (redraw)
- )
- )
- ((= 3 (car gr))
- (setq loop nil)
- (command "_rectang" "_non" ll "_non" ru)
- )
- )
- )
- (redraw)
- (princ)
- )
|