Draw grid line with column
In Architectural drawing, draftman normally draw grid line of building like matrix then place column at intersection of gridlines. This free LISP program will help draftman creating grid line in one command. The GDL command will create gridline after user input these data
Column spacing X:
Column spacing Y:
No. of grid line X:
No. of grid line Y:
Column length (X):
Column width (Y):
Text label Size:
Copy source code below and paste into NOTEPAD and save as <filename>.lsp. Do not forget to choose file type as all filesColumn spacing Y:
No. of grid line X:
No. of grid line Y:
Column length (X):
Column width (Y):
Text label Size:
In PTCAD, user has to use APPLOAD command to load file .lsp .
Then run command GDL
Source code
(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)
)
No comments:
Post a Comment