ACAD LSP File Collection

Here is a tutorial on how to write LSP Files

Create3DFaceAroundText.lsp

Below is an example of a simple AutoLISP script (.lsp file) that creates a 3D face around a piece of text in AutoCAD, effectively hiding entities behind the text. This approach uses the 3DFACE command to create a polygonal face that encloses the text area, and it uses the TEXT command to place the text in the desired location.This AutoLISP code creates a 3D face around a piece of text to hide any entities beneath it in AutoCAD.

(defun c:Create3DFaceAroundText (/ pt1 pt2 pt3 pt4 text-height)
  (setq pt1 (getpoint "\nSpecify the first corner of the text area: "))  ; First corner of the bounding box
  (setq pt2 (getpoint pt1 "\nSpecify the second corner of the text area: "))  ; Opposite corner of the bounding box
  (setq text-height (getreal "\nSpecify the text height: "))  ; Text height to calculate 3D face size
  
  ; Calculate the other two corners of the bounding box based on the input
  (setq pt3 (list (car pt1) (cadr pt2) (last pt1))) ; Third point
  (setq pt4 (list (car pt2) (cadr pt1) (last pt2))) ; Fourth point
  
  ; Create 3D Face
  (command "3dface" pt1 pt2 pt4 pt3)  ; Create a 3D face around the text area

  ; Create the text object
  (setq txt (getstring "\nEnter the text: "))
  (command "text" pt1 text-height 0 txt)  ; Place the text at the specified location
  
  (princ "\n3D Face and text created successfully.")
  (princ)
)

; LSP file by Tim Davis
; To use: Load the LISP file and then type 'Create3DFaceAroundText' in the command line

 

PurgeWithoutVerify.lsp
Purges the drawing without verifying every purge
Below is an AutoLISP script that purges the drawing without verifying every purge. Normally, AutoCAD prompts you to confirm purging unused objects like blocks, layers, or linetypes. This script bypasses those prompts and automatically purges everything, which can be helpful for cleaning up a drawing quickly.
(defun c:PurgeWithoutVerify ()
  (vl-load-com)
  
  ;; Suppress the confirmation prompts during purge
  (setvar 'cmdecho 0) ; Disable command echo to suppress the prompts

  ;; Purge all unused items (blocks, layers, linetypes, etc.)
  (command "_.-PURGE" "_ALL" "_N")

  ;; Optionally, you can add a second call to purge "regapps" (if you want to remove registered applications)
  (command "_.-PURGE" "regapps" "_N")

  ;; Re-enable the command echo after purging
  (setvar 'cmdecho 1)

  (princ "\nPurge completed without verification.")
  (princ)
)

; LSP file by Tim Davis 
; To use: Load the LISP file and type 'PurgeWithoutVerify' in the command line