Here’s is a great little routine that will erase everything that is outside of or crosses a selection window that you create.
This is useful for erasing objects that may have gone astray in a layout tab…
Here’s How:
- DOUT <enter> to start
- Make a window selection. Note: Doesn’t matter what type of selection window ex. crossing…
Everything the crosses the window and lies outside of the window will be erased.
~enjoy
;------------------------------------------------------------------------------ ; PROCEDURE NAME: DOUT.LSP ; ; FUNCTIONAL DESCRIPTION: This is a complement of ERASE WINDOW. ; It will delete all entities OUTSIDE OF or CROSSING a selected window. ; ; CALLED BY: interactive ; ; CALLS: none ; ; PARAMETERS: none ; ; INPUT: interactive ; ; OUTPUT: none ; ; HEADER FILES: n/a ; ; RETURN VALUES: none ; ; CREATED BY / DATE: Daniel J. Squires, CADENCE May 92 p. 89 ; UPLOADED BY: M. Shrout, CDOT R-4 Design (303) 350-2155 06/02/92 ; ; MODIFIED BY / REASON / DATE: ; ; PRECONDITIONS, POSTCONDITIONS: ; ; SIDE EFFECTS / EXCEPTIONS: If any portion of an entity is outside of the ; selected window, that entity will be deleted (as in a "crossing" ; selection set). ;------------------------------------------------------------------------------ ; The program (defun c:DOUT (/ ss1 ss2 ss3) (setq cmd (getvar "CMDECHO")) (setvar "CMDECHO" 0) (setq picked nil) (setq cntr1 0) (setq cntr2 0) (setq cntr3 0) (setq cntr4 0) (setq cntr6 0) (setq ss3 (ssadd)) ; Define selection set #1 (entities to be retained) (while (not picked) (prompt "\nWindow entities to be retained: ")(prin1) (setq pt1 (getpoint "\nFirst window point: ")) (setq pt2 (getcorner pt1 "\nOpposite corner: ")) ; (setq ss1 (ssget "w" pt1 pt2)) (if (/= ss1 nil) (progn (prompt "\nWorking...")(prin1) (setq ss1lng (sslength ss1)) (setq picked 0)) (progn (prompt "\nERROR: No Entities Found - Select Again...") (prin1)) ) ) ; Find all layers in current drawing (setq lyr (tblnext "layer" T)) (while (/= cntr3 nil) (if (and (or (= (cdr (assoc 70 lyr)) 64) (= (cdr (assoc 70 lyr)) 0) ) (/= (minusp (cdr (assoc 62 lyr))) T) ) (progn (setq incrval (itoa cntr4)) (setq cntr4 (1+ cntr4)) (set (read (strcat "lyr" incrval)) (cons 8 (cdr (assoc 2 lyr)))) (setq lyr (tblnext "layer"))) (setq lyr (tblnext "layer")) ) (cond ((= lyr nil) (setq cntr3 nil)) ) ) ; Build delection set #2 & #3 (of displayed entities) (setq cntr5 (1- cntr4)) (setq cntr4 0) (while (<= cntr4 cntr5) (setq incrval (itoa cntr4)) (setq ss2 (ssget "x" (list (eval (read (strcat "lyr" incrval)))))) (if (/= ss2 nil) (progn (while (< cntr6 (sslength ss2)) (setq enty (ssname ss2 cntr6)) (setq ss3 (ssadd enty ss3)) (setq cntr6 (1+ cntr6)) ) ) ) (setq cntr4 (1+ cntr4)) (setq cntr6 0) ) ; Determine if entities exist in both selection sets (#2 & #3) (setq ss2 (ssadd)) (while (< cntr2 (sslength ss3)) (setq entnm3 (ssname ss3 cntr2)) (if (not (ssmemb entnm3 ss1)) (progn (setq ss2 (ssadd entnm3 ss2)) (setq cntr2 (1+ cntr2))) (setq cntr2 (1+ cntr2)) ) ) ; Delete all entities outside of defined window (if (/= (sslength ss2) 0) (progn (command ".ERASE" ss2 "") (prompt "\n\n") (princ (sslength ss2)) (princ " entities found & DELETED...") (prin1)) (progn (prompt "\nNO entities found outside defined window...") (prin1)) ) (setvar "CMDECHO" cmd) (prin1) )
hello my dear, lisp is very nice but i need to delete outside of a polyline, and the polyline is not a rectangle. do you have this lisp ? thank you!
Great request!!
I found one that will do what you are asking about. One limitation that this routine has is that it only works if your closed polyline consists of straight segments (no arcs).
I created a post just for you
https://autocadtips.wordpress.com/2012/03/14/trim-and-delete-outside-of-closed-polyline/
~Greg
you are so polite, and it is working awesome, this is more than a wordpress publishing, thank you!
This is a fantastic add-on. Is there a way to exclude entities touching the polyline? My job requires me to delete thousands of circles inside certain polylines but NOT ones that touch/intersect the polyline selected. There must be a radius measurement check somewhere….
Here is a routine that has multiple selection routines within it.
I don’t know where i found this routine, but the author is Giles Chanteau
These routines are for selecting only. So after it makes the selection set, you must delete the objects on your own.
The option that you are looking for is SSOF
~enjoy
How do I use this Lisp in AutoCAD Civil 3D? I’ve loaded it successfully under applications, but in the past I would type in the name of the lisp (DOUT) and it would work. What am I doing wrong?
Thank you for you post.
The routine is so awesome.
Could you please modify this to just delete objects that are completely outside of the window selection (not just the objects touching or crossing the window).
Many thanks.