;;; Draw Table with non transparent background on user selected area
;;; Based on Lee Mac Draw Grid routine and little modified by Igal Averbuh 2016

;;-----------------------=={ Draw Grid }==--------------------;;
;; ;;
;; Dynamically generates a grid with a specified number of ;;
;; rows and columns. ;;
;; Works in all UCS/Views. ;;
;;------------------------------------------------------------;;
;; Author: Lee Mac, Copyright © 2011 - http://www.lee-mac.com ;;
;;------------------------------------------------------------;;
;; Version 1.1 - 13-10-2011 ;;
;;------------------------------------------------------------;;

(defun c:dg nil (LM:grid nil)) ;; Standard
(defun c:dgridd nil (LM:grid t)) ;; Dynamic

;;------------------------------------------------------------;;

(defun LM:grid

( dyn / *error* _getIntwithDefault _getosmode _parsepoint _makegrid _grX g1 gr ls ms os p1 p3 st )

(defun *error* ( msg )
(if (not (wcmatch (strcase msg) "*BREAK,*CANCEL*,*EXIT*"))
(princ (strcat "\nError: " msg))
)
(redraw) (princ)
)

(defun _getIntwithDefault ( msg sym ) (initget 6)
(set sym
(cond
(
(getint
(strcat msg ": "
)
)
)
( (eval sym) )
)
)
)

(defun _getosmode ( os / lst )
(foreach mode
'(
(0001 . "_end")
(0002 . "_mid")
(0004 . "_cen")
(0008 . "_nod")
(0016 . "_qua")
(0032 . "_int")
(0064 . "_ins")
(0128 . "_per")
(0256 . "_tan")
(0512 . "_nea")
(1024 . "_qui")
(2048 . "_app")
(4096 . "_ext")
(8192 . "_par")
)
(if (not (zerop (logand (car mode) os)))
(setq lst (cons "," (cons (cdr mode) lst)))
)
)
(apply 'strcat (cdr lst))
)

(defun _parsepoint ( pt str / _str->lst lst )

(defun _str->lst ( str / pos )
(if (setq pos (vl-string-position 44 str))
(cons (substr str 1 pos) (_str->lst (substr str (+ pos 2))))
(list str)
)
)

(if (wcmatch str "`@*")
(setq str (substr str 2))
(setq pt '(0.0 0.0 0.0))
)

(if
(and
(setq lst (mapcar 'distof (_str->lst str)))
(vl-every 'numberp lst)
(< 1 (length lst) 4)
)
(mapcar '+ pt lst)
)
)

(defun _makegrid ( p1 p3 mode / hd vd hs vs pt )
(setq hd (- (car p3) (car p1))
vd (- (cadr p3) (cadr p1))
hs (/ hd *cols*)
vs (/ vd *rows*)
)
(cond
( (= 5 mode)
(setq pt p1)
(repeat (1+ *cols*)
(grdraw pt (list (car pt) (+ (cadr pt) vd)) 1 1)
(setq pt (list (+ (car pt) hs) (cadr pt)))
)
(setq pt p1)
(repeat (1+ *rows*)
(grdraw pt (list (+ (car pt) hd) (cadr pt)) 1 1)
(setq pt (list (car pt) (+ (cadr pt) vs)))
)
t
)
( (= 3 mode)
(setq pt p1)
(repeat (1+ *cols*)
(entmakex
(list
(cons 0 "LINE")
(cons 10 (trans pt 1 0))
(cons 11 (trans (list (car pt) (+ (cadr pt) vd)) 1 0))
)
)
(setq pt (list (+ (car pt) hs) (cadr pt)))
)
(setq pt p1)
(repeat (1+ *rows*)
(entmakex
(list
(cons 0 "LINE")
(cons 10 (trans pt 1 0))
(cons 11 (trans (list (+ (car pt) hd) (cadr pt)) 1 0))
)
)
(setq pt (list (car pt) (+ (cadr pt) vs)))
)
nil
)
)
)

(defun _grX ( p s c / -s r q )
(setq -s (- s)
r (/ (getvar 'VIEWSIZE) (cadr (getvar 'SCREENSIZE)))
p (trans p 1 3)
)
(grvecs
(list c
(list -s -s) (list s s)
(list -s (1+ -s)) (list (1- s) s)
(list (1+ -s) -s) (list s (1- s))

(list -s s) (list s -s)
(list -s (1- s)) (list (1- s) -s)
(list (1+ -s) s) (list s (1+ -s))
)
(list
(list r 0. 0. (car p))
(list 0. r 0. (cadr p))
(list 0. 0. r 0.)
(list 0. 0. 0. 1.)
)
)
p
)

(_getIntwithDefault "\nSpecify Number of Rows in table " '*rows*)
(_getIntwithDefault "\nSpecify Number of Columns in table " '*cols*)

(if (setq p1 (getpoint "\nSpecify Base Point of table: "))
(cond
( dyn
(setq os (_getosmode (getvar 'OSMODE))
st ""
)
(princ (setq ms "\nSpecify Opposite Corner of table: "))
(while
(progn (setq gr (grread t 15 0) g1 (car gr) p3 (cadr gr))
(cond
( (member g1 '(3 5)) (redraw)
(if
(and
(zerop (logand 16384 (getvar 'OSMODE)))
(setq op (osnap p3 os))
)
(_grX (setq p3 op) 6 20)
)
(_makegrid p1 p3 g1)
)
( (= g1 2)
(cond
( (= 6 p3)
(if (zerop (logand 16384 (setvar 'OSMODE (boole 6 16384 (getvar 'OSMODE)))))
(princ (strcat "\n" ms st))
(princ (strcat "\n" ms st))
)
)
( (= 8 p3)
(if (string '(8 32 8)))
(setq st (substr st 1 (1- (strlen st))))
)
)
t
)
( (< 32 p3 127)
(setq st (strcat st (princ (chr p3))))
)
( (member p3 '(13 32))
(if ( Minimum Number of Lines Reached." ms))
(setq *n (1- *n))
)
)
( (member g2 '(43 61))
(setq *n (1+ *n))
)
( (= 9 g2)
(setq *v (not *v)) t
)
)
)
( (= 3 g1)
(if *v
(progn
(setq h (/ (- (car g2) (car p1)) (1+ *n))
v (- (cadr g2) (cadr p1))
)
(repeat *n (setq p1 (list (+ h (car p1)) (cadr p1) (caddr p1)))
(entmakex
(list
(cons 0 "LINE")
(cons 10 (trans p1 1 0))
(cons 11 (trans (list (car p1) (+ v (cadr p1)) (caddr p1)) 1 0))
)
)
)
)
(progn
(setq h (- (car g2) (car p1))
v (/ (- (cadr g2) (cadr p1)) (1+ *n))
)
(repeat *n (setq p1 (list (car p1) (+ v (cadr p1)) (caddr p1)))
(entmakex
(list
(cons 0 "LINE")
(cons 10 (trans p1 1 0))
(cons 11 (trans (list (+ (car p1) h) (cadr p1) (caddr p1)) 1 0))
)
)
)
)
)
nil
)
)
)
)
)
)
(redraw) (princ)
)

(defun c:TAB ()
(SetVar "cmdecho" 0)
(setq *ERROR* STOP)
(setq p1 (getpoint "\nFIRST CORNER OF TABLE: "))
(setq p3 (getcorner p1 "\nSECOND CORNER OF TABLE: "))
(setq p2 (list (car p1) (cadr p3)))
(setq p4 (list (car p3) (cadr p1)))
(command "PLINE" p1 "W" 0 0 p2 p3 p4 "C")
(while (> (getvar "CmdActive") 0)
(command pause)
)
(setvar "autosnap" 39)
(setvar "osmode" 1)
(c:dg)
;(c:hvlines)
(command "-hatch" "w" "n" p1 p2 p3 p4 "c" "" "p" "s" "co" "t" "255,255,255" "" "")
(command "draworder" "l" "" "b" )

(SetVar "cmdecho" 1)
)
(c:tab)
;

Advertisements