Wednesday, February 19, 2025

Free LISP : Draw grid line with column

 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 files
                




        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)
)

Monday, February 10, 2025

Block count command

 What is the Block Count Command?

The Block Count command helps you automatically count the number of instances of each block used in a drawing. This is very useful for quantity take-offs, BOM (Bill of Materials), or verifying repeated components like symbols, furniture, or fixtures.



How to Use the Block Count Command in PTCAD

Step-by-Step Instructions:

1. Open your drawing in PTCAD where blocks are already inserted.

2. type the command directly.


You can type:

BCOUNT

and press Enter.

then create frame cover all block you want to count.

The command will process the entire model space (or selected area if prompted), and then display a list of blocks used.



A table or report will be generated, showing:

Block name  &  Count (Quantity)

in text format which user can copy to excel or notepad.




Draw mechanical details with PTCAD Plus - MEC

     Draw mechanical details with PTCAD Plus - MEC               PTCAD Plus edition contains many plug-ins  AECplus, MEC, Assetlink which ca...