Jump to content

Recommended Posts

Posted
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.

  • Replies 29
  • Created
  • Last Reply

Top Posters In This Topic

  • ahyin

    15

  • VVA

    6

  • Lee Mac

    5

  • JohnM

    3

Top Posters In This Topic

Posted Images

Posted
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.

Posted

I’m all for learning new ways to do things but why not use the overkill command?

Posted
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)

Posted

where you doing the whole drawing?

could you post the drawing

overkill worked for me

Posted
where you doing the whole drawing?

could you post the drawing

overkill worked for me

hi Johnm

 

Please try the test.dwg

test.zip

Posted

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

Posted
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.

Posted
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 !

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.

Guest
Unfortunately, your content contains terms that we do not allow. Please edit your content to remove the highlighted words below.
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.


×
×
  • Create New...