我刚刚写了这段代码,在屏幕上指定的区域绘制方框,试试看,然后告诉我。
- (defun c:test (/ _poly:box w h a b c d x y p1 p2 p3 w1 h1 lft-1 lft-2 p)
- ;; Tharwat Al Shoufi ;;
- (if
- (and (setq
- *width*
- (cond ((getdist (strcat "\n Specify Width of box <"
- (rtos (cond (*width*)
- ((setq *width* 1.0))
- )
- 2
- 2
- )
- ">: "
- )
- )
- )
- (*width*)
- )
- )
- (setq
- *height* (cond
- ((getdist (strcat "\n Specify Height of box <"
- (rtos (cond (*height*)
- ((setq *height* 1.0))
- )
- 2
- 2
- )
- ">: "
- )
- )
- )
- (*height*)
- )
- )
- (setq a (getpoint "\n Specify base point :"))
- (setq b (getcorner "\n Specify opposite point :" a))
- )
- (progn
- (defun _poly:box (p wid hgt / 1p 2p 3p)
- (entmakex
- (list '(0 . "LWPOLYLINE")
- '(100 . "AcDbEntity")
- '(100 . "AcDbPolyline")
- '(90 . 4)
- '(70 . 1)
- (cons 10 (setq 1p (polar p 0. wid)))
- (cons 10 (setq 2p (polar 1p (* pi 1.5) hgt)))
- (cons 10 (setq 3p (polar 2p pi wid)))
- (cons 10 p)
- )
- )
- (princ)
- )
- (setq c (list (car a) (cadr b))
- d (list (car b) (cadr b))
- x (mapcar 'car (list a b c d))
- y (mapcar 'cadr (list a b c d))
- p1 (list (apply 'min x) (apply 'max y))
- p2 (list (apply 'max x) (apply 'max y))
- p3 (list (apply 'min x) (apply 'min y))
- w *width*
- h *height*
- )
- (if (and (> (setq w1 (distance p1 p2)) w)
- (> (setq h1 (distance p1 p3)) h)
- )
- (progn
- (setq p p1)
- (repeat (fix (/ h1 h))
- (repeat (fix (/ w1 w))
- (_poly:box p1 w h)
- (setq p1 (polar p1 0. w))
- )
- (if (< 0 (setq lft-1 (rem w1 w)))
- (_poly:box p1 lft-1 h)
- )
- (setq p (polar p (* pi 1.5) h)
- p1 p
- )
- )
- (if (< 0 (setq lft-2 (rem h1 h)))
- (progn
- (repeat (fix (/ w1 w))
- (_poly:box p1 w lft-2)
- (setq p1 (polar p1 0. w)
- )
- )
- (_poly:box p1 lft-1 lft-2)
- )
- )
- )
- )
- )
- )
- (princ)
- )
|