Ivan Diaz

Undergraduate Geomatic Engineering Student at California State University, Fresno.

Block-and-Roll.lsp – Automating CAD Work with AutoLISP

Autolisp with Visual Studio Code
Autolisp with Visual Studio Code

Industry Project – Winter 2024

Summary: Rebuilt a personal AutoLISP tool to automate Civil 3D block placement based on point descriptions, reducing repetitive drafting time.

Tools: AutoLISP, Civil 3D, CAD blocks

Skills: Scripting, automation, CAD customization, problem-solving

Outcome: Reduced manual drafting time by automating block placement for point codes

Project Overview: Over winter break, I rewrote a personal AutoLISP tool called `Block-And-Roll.lsp`, which automates CAD block placement in Civil 3D based on point descriptions. The script currently supports ~50 block types. I rebuilt it from scratch using case-switch logic to ensure scalability and maintainability while avoiding overlap with tools developed during my time at Praxis Land Surveying.

Key Skills Gained:


This version preserves the core logic of the original tool but reflects how I approach problem-solving independently. It respects the boundaries of proprietary work and is structured for future customization.

;; BLOCK and ROLL Version 2


(defun c:blockandroll ( / ss x northng pnt eastng descr dist hndl eastng1 eastng2 northng1 northng2 pnt1 pnt2 easting1 nothing1 easting2 northing2 )
  ;;; loads VLISP commands 
  (vl-load-com)
  ;;; Array to hold the values for condition checks
  (setq conditions
    '(
      ("RK" "RK2" "V-TOPO-ROCK" "2")
      ("TCPO" "JP" "V-UTIL-COMM-EQPM" "20")
      ("GWAT" "GWA" "V-UTIL-COMM-EQPM" "20")
    )
  )

  ;;; ssget gets objects by filter 
  (if (ssget "X" '((0 . "AECC_COGO_POINT")))
     (progn
        ;;; vlax-for Iterates through a collection of objects, evaluating each expression  
        (vlax-for x
           (setq ss (vla-get-activeselectionset (vla-get-activedocument (vlax-get-acad-object))))
           (setq pnt (vlax-get x 'number)
              eastng (vlax-get x 'easting)
              northng (vlax-get x 'northing)
              descr (vlax-get x 'rawdescription)
              hndl (vlax-get x 'handle)
           );END setq

           ;; Loop through conditions
           (foreach condition conditions
             (setq key (car condition))
             (setq insert (cadr condition))
             (setq layer (caddr condition))
             (setq scale (cadddr condition))
             (cond
               ((= 0 (vl-string-search key descr)) 
                (progn 
                  (command "clayer" layer) 
                  (command "_insert" insert (list eastng northng) scale "" "") 
                  (command "clayer" "0")
                )
               )
             )
           );END foreach

        );END vlax-for
     );END progn
  );END if

  (princ "\\nTHE CAD DRAWING HAS BEEN")
  (princ "\\nBLOCKED AND ROLLED.")
  (princ)
)

Published: 2025-05-03 19:22:00