(defun IntToAlpha (n / a r s)
(setq s "")
(while (> n 0)
(setq r (rem (1- n) 26))
(setq a (+ 65 r))
(setq s (strcat (chr a) s))
(setq n (/ (1- n) 26))
)
s
)
(defun c:GDL ( / basePt xSpacing ySpacing xCount yCount colW colH i j x y cx cy pt1 pt2 pt3 pt4 txtH rad ptC ptL)
;; š§ Layer setup
(foreach lay '(("GRID" 5 "DASHED") ("COL" 7 "") ("GRID-TEXT" 2 ""))
(if (not (tblsearch "LAYER" (car lay)))
(progn
(command "_.LAYER" "M" (car lay) "C" (itoa (cadr lay)) "" "L" (caddr lay) "" "")
(if (and (not (tblsearch "LTYPE" (caddr lay))) (/= (caddr lay) ""))
(command "_.-LINETYPE" "LOAD" (caddr lay) "" "")
)
)
)
)
;; š User input
(prompt "\nSelect start point (lower left corner):")
(setq basePt (getpoint))
(setq xSpacing (getreal "\nColumn spacing X: "))
(setq ySpacing (getreal "\nColumn spacing Y: "))
(setq xCount (getint "\nNo. of grid line X: "))
(setq yCount (getint "\nNo. of grid line Y: "))
(setq colW (getreal "\nColumn length (X): "))
(setq colH (getreal "\nColumn width (Y): "))
(setq txtH (getreal "\nText label Size: "))
(setq rad (/ txtH 1.5)) ; circle radius
;; š Draw grid
(setvar 'CLAYER "GRID")
(setq i 0)
(while (< i xCount)
(setq x (+ (car basePt) (* i xSpacing)))
(command "_.LINE" (list x (cadr basePt)) (list x (+ (cadr basePt) (* (- yCount 1) ySpacing))) "")
(setq i (1+ i))
)
(setq j 0)
(while (< j yCount)
(setq y (+ (cadr basePt) (* j ySpacing)))
(command "_.LINE" (list (car basePt) y) (list (+ (car basePt) (* (- xCount 1) xSpacing)) y) "")
(setq j (1+ j))
)
;; š Place column
(setvar 'CLAYER "COL")
(setq i 0)
(while (< i xCount)
(setq j 0)
(while (< j yCount)
(setq cx (+ (car basePt) (* i xSpacing)))
(setq cy (+ (cadr basePt) (* j ySpacing)))
(setq pt1 (list (- cx (/ colW 2)) (- cy (/ colH 2))))
(setq pt2 (list (+ cx (/ colW 2)) (- cy (/ colH 2))))
(setq pt3 (list (+ cx (/ colW 2)) (+ cy (/ colH 2))))
(setq pt4 (list (- cx (/ colW 2)) (+ cy (/ colH 2))))
(command "_.PLINE" pt1 pt2 pt3 pt4 "C")
(setq j (1+ j))
)
(setq i (1+ i))
)
;; š· place Label (Layer GRID-TEXT)
(setvar 'CLAYER "GRID-TEXT")
;; š axis X ā A, B, C...
(setq i 0)
(while (< i xCount)
(setq x (+ (car basePt) (* i xSpacing)))
(setq y (+ (cadr basePt) (* ySpacing yCount)))
(setq ptC (list x (+ y rad))) ; center of circle
(setq ptL (list x (- y yspacing))) ; target: gridline
(setq ptStart (list x (- (+ y rad) rad))) ; bottom of circle
;; Draw label circle-text-line
(command "_.CIRCLE" ptC rad)
(command "_.LINE" ptStart ptL "")
(command "_.TEXT" "J" "MC" ptC txtH "0" (IntToAlpha (1+ i)))
(setq i (1+ i))
)
;; š¢ axis Y ā 1, 2, 3...
(setq j 0)
(while (< j yCount)
(setq y (+ (cadr basePt) (* j ySpacing)))
(setq x (- (car basePt) (* 0.5 xSpacing)))
(setq ptC (list (- x rad) y)) ; center of circle
(setq ptL (list (car basePt) y)) ; target: gridline
(setq ptStart (list x y)) ; right of circle
;; Draw label circle-text-line
(command "_.CIRCLE" ptC rad)
(command "_.LINE" ptStart ptL "")
(command "_.TEXT" "J" "MC" ptC txtH "0" (itoa (1+ j)))
(setq j (1+ j))
)
(prompt "\nā
Draw label circle-text-line completed.")
(princ)
)