Erase All But...

Erase All But...

msarqui
Collaborator Collaborator
3,149 Views
5 Replies
Message 1 of 6

Erase All But...

msarqui
Collaborator
Collaborator

Hi guys,

 

I have this idea in mind for a long time and I would like to ask if it is possible to execute.
In the attached file, I have several rectangles. Notice that the rectangles are always in a specific layer. Also, I have several objects drawn (it could be any kind of AutoCAD object in any possible layer).


My question is:
Could I have a routine that will erase all the objects that are completely outside those rectangles? I know I can type ERASE, ALL and then REMOVE those rectangles areas with a window selection but in a large file this will be a waste of time.

Notice that some rectangles are overlapping, or within each other. So the routine should only consider the largest rectangle, or their outer boundary. I know Lee have this routine to make outline of selected objects http://www.lee-mac.com/outlineobjects.html (maybe it could be a start...)


I have AutoCAD 2012 but soon we will change for 2016.
Thanks!

0 Likes
Accepted solutions (1)
3,150 Views
5 Replies
Replies (5)
Message 2 of 6

ВeekeeCZ
Consultant
Consultant

Try this one...

 

(vl-load-com)

(defun C:EraseOutside (/ en ss sa si sai i ed e pts ) 

  (if (and (setq en (car (entsel "\nSelect countour object for layer: ")))
           (setq ss (ssget "_A" (list (assoc 8 (entget en)))))
	   (setq sa (ssget "_A" (list (cons 8 (strcat "~" (cdr (assoc 8 (entget en))))))))
	   (setq sai (ssadd))
	   )
    (repeat (setq i (sslength ss))
      (setq ed (entget (ssname ss (setq i (1- i))))
	    pts (mapcar 'cdr (vl-remove-if-not '(lambda (x) (= (car x) 10)) ed)))
      (if (setq si (ssget "_CP" pts))
        (repeat (setq n (sslength si))
	  (if (not (ssmemb (setq e (ssname si (setq n (1- n)))) sai))
	    (ssadd e sai))))))
  (if sai (repeat (setq i (sslength sai))
	    (ssdel (ssname sai (setq i (1- i))) sa)))
  (if sa (command "_.ERASE" sa ""))
  (princ)
)

 

0 Likes
Message 3 of 6

ВeekeeCZ
Consultant
Consultant
Accepted solution

One more look into it... two loops looks like just enough.

 

(vl-load-com)

(defun C:EraseOutside (/ en ss sa si i) 
  (if (and (setq en (car (entsel "\nSelect contour: ")))
           (setq ss (ssget "_A" (list (assoc 8 (entget en)))))
	   (setq sa (ssget "_A" (list (cons 8 (strcat "~" (cdr (assoc 8 (entget en))))))))
	   )
    (repeat (setq i (sslength ss))
      (if (setq si (ssget "_CP" (mapcar 'cdr (vl-remove-if-not
					       '(lambda (x) (= (car x) 10))
					       (entget (ssname ss (setq i (1- i))))))))
        (repeat (setq n (sslength si))
	  (if (ssmemb (setq e (ssname si (setq n (1- n)))) sa)
	    (ssdel e sa))))))
  (if sa (command "_.ERASE" sa ""))
  (princ)
)
0 Likes
Message 4 of 6

msarqui
Collaborator
Collaborator

Working like a charm.
Thank you very much BeekeeCZ!

0 Likes
Message 5 of 6

Anonymous
Not applicable
 
 
 
from esteem of structural software (beam and slab section) .. every detail is disorganized .. what LSP can do automatic stacking this section beam and slab in one tittle block  ..tq
0 Likes
Message 6 of 6

msarqui
Collaborator
Collaborator

If you are also interested on this routine please go HERE to watch the final chapter!

0 Likes