Author Topic: Thoughts on a better ERASE command  (Read 3937 times)

0 Members and 1 Guest are viewing this topic.

Dave M

  • Newt
  • Posts: 195
Thoughts on a better ERASE command
« on: June 14, 2012, 10:25:45 PM »
Allow me to throw down the gauntlet, and see if any skillful swampers have a routine that would work like I'm about to describe. 

A polyline is created, and when you invoke the erase command (or any command that allows crossing polygon or window polygon), you have the ability to use the polyline you just created as either a window polygon, or a crossing polygon for selection.

Your reward?  My undying appreciation  ;-)
Civil 3D 2018 - Microstation SS4 - Windows 10 - Dropbox

ronjonp

  • Needs a day job
  • Posts: 7282
Re: Thoughts on a better ERASE command
« Reply #1 on: June 14, 2012, 10:48:42 PM »
Grab the polyline coordinates then use ssget and wp?

Windows 10 x64 - AutoCAD /C3D 2020

Custom Build PC

danallen

  • Guest
Re: Thoughts on a better ERASE command
« Reply #2 on: June 14, 2012, 11:08:22 PM »
Here is code for selecting:

Code: [Select]
;;;From: Joe Burke (joburke@hawaii.rr.com)
;;;Subject: Re: Polygon Selection Boundary
;;;Newsgroups: autodesk.autocad.customization
;;;Date: 2002-04-17 04:38:49 PST
;;;
;;;returns list of points in a pline
(defun-q C:SelectByPline (/ pline ptlist prev count)
 (princ "\nCrossing or Window selection?<C,W>")
 (setq typ (strcase (getstring)))
 (cond
  ((= typ "W")
   (prompt "\nPick polyline to define Window selection set:")
  )
  ((= typ "C")
   (prompt "\nPick polyline to define Crossing selection set:")
  )
 )
 (setq pline (car (entsel))
       ptlist (massoc 10 (entget pline))
 )
 (cond
  ((= typ "W")
   (setq prev (ssget "WP" ptlist))
   (setq count (sslength prev))
   (princ "\nThe Selection Set consists of ")
   (princ count)
   (princ " entities inside the Window Polygon.")
  )
  ((= typ "C")
   (setq prev (ssget "CP" ptlist))
   (ssdel pline prev) ;remove pline from crossing ss
   (setq count (sslength prev))
   (princ "\nThe Selection Set consists of ")
   (princ count)
   (princ " entities inside the Crossing Polygon.")
  )
 )
 (sssetfirst nil prev) ;select
 (princ)
);end defun

;;;=========================================================================
;;; massoc
;;;
;;; get multiple items from an association list (instead of just 1st one)
;;;
;;; From: Tony Tanzillo (tony.tanzillo@worldnet.att.net)
;;; Subject: Re: extracting multiple assoc from list
;;; Newsgroups: autodesk.autocad.customization
;;; Date: 1999/09/29
;;;=========================================================================
(defun-q massoc (key alist / x nlist)
  (foreach x alist
    (if (eq key (car x))
      (setq nlist (cons (cdr x) nlist))
    )
  )
  (reverse nlist)
) ;end defun


irneb

  • Water Moccasin
  • Posts: 1794
  • ACad R9-2016, Revit Arch 6-2016
Re: Thoughts on a better ERASE command
« Reply #3 on: June 15, 2012, 04:13:33 AM »
Slightly more concise:
Code - Auto/Visual Lisp: [Select]
  1.  
  2. (defun massoc (key lst /)
  3.   (mapcar 'cdr (vl-remove-if-not '(lambda (item) (equal key (car item))) lst)))
  4.  
  5. (defun c:EraseByPoly  (/ pEname pDxf ss)
  6.   (or *W/C* (setq *W/C* "CP"))
  7.   (while (progn (initget "CP WP F Undo")
  8.                 (setq pEname (entsel (strcat "\nSelect polyline border [WP/CP/F/Undo] <" *W/C* ">: "))))
  9.     (cond ((eq (type pEname) 'Str)
  10.            (if (eq pEname "Undo")
  11.              (command "_.Undo" "1")
  12.              (setq *W/C* pEname)))
  13.           ((and (eq (type pEname) 'List)
  14.                 (eq (type (setq pEname (car pEname))) 'EName)
  15.                 (eq (cdr (assoc 0 (setq pDxf (entget pEname)))) "LWPOLYLINE"))
  16.            (if (setq ss (ssget *W/C* (massoc 10 pDxf)))
  17.              (command "_.ERASE" (ssdel pEname ss) "")
  18.              (prompt "\nThere's no objects to erase.")))
  19.           (t (prompt "\nThat's not a polyline, please try again."))))
  20.   (princ))
Though for some reason I'm finding nothing selected through WP. Works fine for CP/F selection though.
Common sense - the curse in disguise. Because if you have it, you have to live with those that don't.

Lee Mac

  • Seagull
  • Posts: 12489
  • London, England
Re: Thoughts on a better ERASE command
« Reply #4 on: June 15, 2012, 08:05:44 AM »
My version:

Code - Auto/Visual Lisp: [Select]
  1. (defun c:perase ( / e s )
  2.     (while
  3.         (progn (setvar 'errno 0) (setq e (car (entsel)))
  4.             (cond
  5.                 (   (= 7 (getvar 'errno))
  6.                     (princ "\nMissed, try again.")
  7.                 )
  8.                 (   (eq 'ename (type e))
  9.                     (if (not (eq "LWPOLYLINE" (cdr (assoc 0 (entget e)))))
  10.                         (princ "\nSelected Object is not an LWPolyline.")
  11.                     )
  12.                 )
  13.             )
  14.         )
  15.     )
  16.     (if
  17.         (and e
  18.             (progn
  19.                 (initget "Window Crossing")
  20.                 (setq s
  21.                     (ssget
  22.                         (cond
  23.                             (   (eq "Window" (getkword "\nSpecify Selection Type [Window/Crossing] <Crossing>: "))
  24.                                 "_WP"
  25.                             )
  26.                             (   "_CP"   )
  27.                         )
  28.                         (apply 'append (mapcar '(lambda ( x ) (if (= 10 (car x)) (list (cdr x)))) (entget e)))
  29.                     )
  30.                 )
  31.                 (if s (ssdel e s))
  32.                 (< 0 (sslength s))
  33.             )
  34.         )
  35.         (command "_.erase" s "")
  36.     )
  37.     (princ)
  38. )

@Irné, hint: if pEname is not a member of ss, ssdel returns nil :wink:

irneb

  • Water Moccasin
  • Posts: 1794
  • ACad R9-2016, Revit Arch 6-2016
Re: Thoughts on a better ERASE command
« Reply #5 on: June 15, 2012, 08:50:59 AM »
@Irné, hint: if pEname is not a member of ss, ssdel returns nil ;)
Ah!  :-[ ... thanks for turning on the light! And for reminding me I don't need the vl-remove-* functions to get rid of nils: append does the same thing.

Now this works!
Code - Auto/Visual Lisp: [Select]
  1. (defun massoc  (key lst /)
  2.   (apply 'append (mapcar '(lambda (item) (if (equal key (car item)) (list (cdr item)))) lst)))
  3.  
  4. (defun c:EraseByPoly  (/ pEname pDxf ss)
  5.   (or *W/C* (setq *W/C* "CP"))
  6.   (while (progn (initget "CP WP F Undo")
  7.                 (setq pEname (entsel (strcat "\nSelect polyline to [WP/CP/F/Undo] <" *W/C* ">: "))))
  8.     (cond ((eq (type pEname) 'Str)
  9.            (if (eq pEname "Undo")
  10.              (command "_.Undo" "1")
  11.              (setq *W/C* pEname)))
  12.           ((and (eq (type pEname) 'List)
  13.                 (eq (type (setq pEname (car pEname))) 'EName)
  14.                 (eq (cdr (assoc 0 (setq pDxf (entget pEname)))) "LWPOLYLINE"))
  15.            (if (and (setq ss (ssget *W/C* (massoc 10 pDxf)))
  16.                     (progn (ssdel pEname ss)
  17.                       (> (sslength ss) 0)))
  18.              (command "_.ERASE" ss "")
  19.              (prompt "\nThere's no objects to erase.")))
  20.           (t (prompt "\nThat's not a polyline, please try again."))))
  21.   (princ))
Common sense - the curse in disguise. Because if you have it, you have to live with those that don't.

Dave M

  • Newt
  • Posts: 195
Re: Thoughts on a better ERASE command
« Reply #6 on: June 18, 2012, 11:43:58 AM »
Lee,

Thanks, this works perfectly!

Dave
Civil 3D 2018 - Microstation SS4 - Windows 10 - Dropbox

Lee Mac

  • Seagull
  • Posts: 12489
  • London, England
Re: Thoughts on a better ERASE command
« Reply #7 on: June 18, 2012, 11:51:02 AM »
You're very welcome Dave, I hope the code is comprehensible  :-)

huiz

  • Swamp Rat
  • Posts: 885
  • Certified Prof C3D
Re: Thoughts on a better ERASE command
« Reply #8 on: June 18, 2012, 03:24:13 PM »
I've seen a CookieCutter lisp somewhere which also erases everything inside or outside a polyline, and cut every line and block. Very usefull kind-of-an-erase tool. Actually, erase is an option but not required.

Another maybe great idea for a better erase command is to put elements in a recycle bin or something like that. If you open that drawing recycle bin, you see a drawing with everything you've erased and the possibility to restore the element.
The conclusion is justified that the initialization of the development of critical subsystem optimizes the probability of success to the development of the technical behavior over a given period.

CAB

  • Global Moderator
  • Seagull
  • Posts: 10395
Re: Thoughts on a better ERASE command
« Reply #9 on: June 18, 2012, 03:48:14 PM »
http://www.theswamp.org/index.php?topic=24646.0  Trim with objects [CookieCutter] by Joe Burke
I've reached the age where the happy hour is a nap. (°¿°)
Windows 10 core i7 4790k 4Ghz 32GB GTX 970
Please support this web site.

dgorsman

  • Water Moccasin
  • Posts: 2434
Re: Thoughts on a better ERASE command
« Reply #10 on: June 18, 2012, 04:50:50 PM »
Another maybe great idea for a better erase command is to put elements in a recycle bin or something like that. If you open that drawing recycle bin, you see a drawing with everything you've erased and the possibility to restore the element.

Like something that wblocks out the chunks (or even individual entities) as they are erased?
If you are going to fly by the seat of your pants, expect friction burns.

try {GreatPower;}
   catch (notResponsible)
      {NextTime(PlanAhead);}
   finally
      {MasterBasics;}

huiz

  • Swamp Rat
  • Posts: 885
  • Certified Prof C3D
Re: Thoughts on a better ERASE command
« Reply #11 on: June 19, 2012, 03:45:48 AM »
Another maybe great idea for a better erase command is to put elements in a recycle bin or something like that. If you open that drawing recycle bin, you see a drawing with everything you've erased and the possibility to restore the element.

Like something that wblocks out the chunks (or even individual entities) as they are erased?

Conceptual thinking, it would be very cool to have a recycle bin inside the drawing. Colleagues are able to undo erase actions, but customers shouldn't see the deleted items. So I think keeping the erased stuff inside the drawing is not a very good idea.

Maybe WBLOCK is an option. But your disk will be filled with garbage and it is hard to chain the erased elements to the original drawing.

I just think of another method, still conceptual (and I'm not sure if I will create this, but maybe I once will do ;-) ) what if there is an application which uses a Layout as a recycle bin. It redefines the ERASE command or using a reactor so the erased elements are moved to the Layout. The elements can keep the layer, color and linetype information. So all the elements are easily accessible to be restored, and it is also very easy to remove the Recycle Bin layout before sending the drawing to the customer.
The conclusion is justified that the initialization of the development of critical subsystem optimizes the probability of success to the development of the technical behavior over a given period.

irneb

  • Water Moccasin
  • Posts: 1794
  • ACad R9-2016, Revit Arch 6-2016
Re: Thoughts on a better ERASE command
« Reply #12 on: June 19, 2012, 04:22:32 AM »
You could always "send" the erased objects to a non-referenced block definition inside the DWG. That way the "trashbin" is not displayed in the DWG but easily restored by simply inserting that block @ 0,0,0 and exploding it. You could then wblock that block if you so want, or to clear it do a purge.
Common sense - the curse in disguise. Because if you have it, you have to live with those that don't.

huiz

  • Swamp Rat
  • Posts: 885
  • Certified Prof C3D
Re: Thoughts on a better ERASE command
« Reply #13 on: June 19, 2012, 04:26:21 AM »
That is also a neat solution.
The conclusion is justified that the initialization of the development of critical subsystem optimizes the probability of success to the development of the technical behavior over a given period.

dgorsman

  • Water Moccasin
  • Posts: 2434
Re: Thoughts on a better ERASE command
« Reply #14 on: June 19, 2012, 10:18:30 AM »
You could always "send" the erased objects to a non-referenced block definition inside the DWG. That way the "trashbin" is not displayed in the DWG but easily restored by simply inserting that block @ 0,0,0 and exploding it. You could then wblock that block if you so want, or to clear it do a purge.

Slick.  Or something along the lines of the autosave cleaner which (under normal circumstances) cleans up after itself if the drawing is closed normally.
If you are going to fly by the seat of your pants, expect friction burns.

try {GreatPower;}
   catch (notResponsible)
      {NextTime(PlanAhead);}
   finally
      {MasterBasics;}