ahyin Posted June 13, 2011 Author Posted June 13, 2011 I'm sure Lee wouldn't mind this:(defun c:test (/ LM:UniqueFuzz LM:MAssoc ss i e) (vl-load-com) ;; © Lee Mac 2011 (defun LM:UniqueFuzz-p (lst fuzz) ;Define a localized defun inside c:test (or (null lst) ;If lst is empty - or (and ;and the 2 following apply (not (vl-member-if ;The following is not a member of the residual of lst '(lambda (x) (equal x (car lst) fuzz)) ;Temporary function to check equality to a fuzz of the 1st item in lst (cdr lst) ;The residual of lst ) ) (LM:UniqueFuzz-p (cdr lst) fuzz) ;Call this function again with the residual of the list ) ) ) (defun LM:MAssoc (key lst / pair) ;Define a localized defun inside c:test (if (setq pair (assoc key lst)) ;Check if there is an assoc (cons (cdr pair) ;Return a new list containing the 1st assoc found, plus ;;The other assocs found by calling this same function with only the residual of the list (LM:MAssoc key (cdr (member pair lst))) ) ) ) (if (setq ss (ssget "_X" '((0 . "LWPOLYLINE")))) ;If any LWPolies found (repeat (setq i (sslength ss)) ;Loop through each ;; Use the above 2 functions to check if the current one is unique (if (LM:UniqueFuzz-p (LM:MAssoc 10 (entget (setq e (ssname ss (setq i (1- i)))))) 1e- (ssdel e ss) ;Then remove it from the selection set ) ) ) (sssetfirst nil ss) ;Select the resulting selection set (princ) ) It uses recursion extensively ... something which you'll find a lot in lisp. I.e. a function calling itself in order form a loop. This is sometimes better / easier / more efficient than using the normal while / repeat / etc. loops. In the above case it's one of these times. Also notice Lee's stepping through the list from the last entity - decrementing the i (index) variable. There's 2 reasons behind this: (1) it's slightly more efficient than the other way round; and (2) because he's removing elements from the selection set, the length changes - thus if #4 is remove, then the old #5 becomes the new #4, so incrementing i would skip some items. Thanks you clearly explanation, it is more easy to understand. Quote
VVA Posted June 13, 2011 Posted June 13, 2011 VVA, just curious, why: (mapcar '+ < .. > '(0 0)) Obviously the (0 0) is not affecting the result in any way so are you using this method to ensure the return from mapcar is a 2D point? Yes, I'm such a way to remove the coordinate z. Although more research I did not hold. Possible, list will run faster. Quote
JohnM Posted June 13, 2011 Posted June 13, 2011 I’m all for learning new ways to do things but why not use the overkill command? Quote
ahyin Posted June 14, 2011 Author Posted June 14, 2011 I’m all for learning new ways to do things but why not use the overkill command? I try to use overkill command but a very simple drawing have the following error, I don't why ? Initializing... Initializing... Initializing... Initializing...Hard error occurred *** internal stack limit reached (simulated) Quote
JohnM Posted June 14, 2011 Posted June 14, 2011 where you doing the whole drawing? could you post the drawing overkill worked for me Quote
ahyin Posted June 14, 2011 Author Posted June 14, 2011 where you doing the whole drawing?could you post the drawing overkill worked for me hi Johnm Please try the test.dwg test.zip Quote
JohnM Posted June 14, 2011 Posted June 14, 2011 I did not receive any errors Play with the command and see what it can do The big object worked out ok The 2 small ones did not because there was a zero length line at the top left point Quote
Lee Mac Posted June 14, 2011 Posted June 14, 2011 I try to use overkill command but a very simple drawing have the following error, I don't why ? Initializing... Initializing... Initializing... Initializing...Hard error occurred *** internal stack limit reached (simulated) I've seen this happen with other Express Tools LISP functions that are loaded using the acet-autoload2 function - it is usually caused by having another LISP file in the Support Path with the same filename as that of an Express Tool LISP, but with a different command syntax. The same problem was experienced here. Quote
ahyin Posted June 15, 2011 Author Posted June 15, 2011 I've seen this happen with other Express Tools LISP functions that are loaded using the acet-autoload2 function - it is usually caused by having another LISP file in the Support Path with the same filename as that of an Express Tool LISP, but with a different command syntax. The same problem was experienced here. Thank you ! I have already register, and I will check it later. Lee Mac can you give me a hand, I want draw the polylines again on top of existing polyline by "bpoly "command based on the your selected result. How to write is code ? Thank you very much ! Quote
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.
Note: Your post will require moderator approval before it will be visible.