TheSwamp
Code Red => AutoLISP (Vanilla / Visual) => Topic started by: Dave M 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 ;-)
-
Grab the polyline coordinates then use ssget and wp?
-
Here is code for selecting:
;;;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
-
Slightly more concise:
(defun massoc
(key lst
/)
(defun c:EraseByPoly
(/ pEname pDxf ss
) (setq pEname
(entsel (strcat "\nSelect polyline border [WP/CP/F/Undo] <" *W
/C
* ">: ")))) (prompt "\nThere's no objects to erase."))) (t
(prompt "\nThat's not a polyline, please try again."))))
Though for some reason I'm finding nothing selected through WP. Works fine for CP/F selection though.
-
My version:
(defun c:perase
( / e s
) (princ "\nMissed, try again.") )
(princ "\nSelected Object is not an LWPolyline.") )
)
)
)
)
( (eq "Window" (getkword "\nSpecify Selection Type [Window/Crossing] <Crossing>: ")) "_WP"
)
( "_CP" )
)
)
)
)
)
)
)
@Irné, hint: if pEname is not a member of ss, ssdel returns nil :wink:
-
@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!(defun massoc
(key lst
/)
(defun c:EraseByPoly
(/ pEname pDxf ss
) (setq pEname
(entsel (strcat "\nSelect polyline to [WP/CP/F/Undo] <" *W
/C
* ">: ")))) (prompt "\nThere's no objects to erase."))) (t
(prompt "\nThat's not a polyline, please try again."))))
-
Lee,
Thanks, this works perfectly!
Dave
-
You're very welcome Dave, I hope the code is comprehensible :-)
-
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.
-
http://www.theswamp.org/index.php?topic=24646.0 Trim with objects [CookieCutter] by Joe Burke
-
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?
-
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.
-
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.
-
That is also a neat solution.
-
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.
-
Or work similar to a normal Trash-Bin. I.e. have a setting to specify a maximum amount of entities to keep (could be as a percentage of the entire DWG). That way only keep the latest entities and delete the older ones - it should be sorted by time of deletion in any case (if you simply keep adding them to the block def).
-
Or try making them invisible:
http://www.theswamp.org/index.php?topic=5007.msg60596#msg60596 (http://www.theswamp.org/index.php?topic=5007.msg60596#msg60596)
-
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.
You could always "send" the erased objects to a non-referenced block definition inside the DWG.
That's a great idea Irné! 8-)
Attached is my first draft of a possible program which implements this proposed method to give us all something to work with.
The 'recycle' command will move a selection of objects to the 'drawing recycle bin', and the 'restore' command will restore objects that were previously recycled. The recycle bin can be 'emptied' by simply purging the block collection.
Feel free to add comments and suggestions :-)
-
It is really great Lee Mac! 8) Great to see ideas come to life!
Maybe, if it is not asked too much, a preview of the selected restore item? In big red lines? :-)
-
It is really great Lee Mac! 8) Great to see ideas come to life!
Thank you huiz :-)
Maybe, if it is not asked too much, a preview of the selected restore item? In big red lines? :-)
This would certainly be possible by inserting the 'recycled' block into the drawing and perhaps drawing a box around it using grvecs / grdraw to make it easily distinguishable from surrounding objects, but since standard DCL only permits modal dialogs, the dialog would need to be suppressed and then reloaded if the user cancels the preview (similar to the preview option of the Array command).
-
Actually better than cut with basepoint as it allows both, multiple separate erased and saved with file! Anyway the restore could ask/allow an alternate or original point/location to restore to?
-
Actually better than cut with basepoint as it allows both, multiple separate erased and saved with file! Anyway the restore could ask/allow an alternate or original point/location to restore to?
Yes - change this:
To:
Note that the base point is always relative to the drawing origin however.
-
Lee.. anyway you could help me rework this to acquire the
insert cut point upon picking object(s) instead of the (0.0 0.0 0.0) as in your "DrawingRecycleBin" Please? :idea:
(vla-get-blocks ad)
'add
'(0.0 0.0 0.0) << would help! Wish to understand how to get
a coord (getpoint..) to work.
Thanks so much!
-
Wow, I get engrossed in doing what I need to fix up and this is what I come back to find! There is some incredible stuff here.