TheSwamp

Code Red => AutoLISP (Vanilla / Visual) => Topic started by: Grrr1337 on March 10, 2020, 03:28:19 AM

Title: Avoid Hatches Sel - Reactor
Post by: Grrr1337 on March 10, 2020, 03:28:19 AM
Hey guys,
Currently I've got this working -
Code - Auto/Visual Lisp: [Select]
  1. (defun AvoidHatches:CB (rtr args / L )
  2.   (and
  3.    
  4.     (setq L
  5.       (
  6.         (lambda ( SS / i o L )
  7.           (if
  8.             (and SS
  9.               (repeat (setq i (sslength SS))
  10.                 (setq o (vlax-ename->vla-object (ssname SS (setq i (1- i)))))
  11.                 (setq L (cons o L))
  12.               ); repeat
  13.               (vl-some (function (lambda (o) (eq "AcDbHatch" (vla-get-ObjectName o)))) L)
  14.               (setq L (vl-remove-if (function (lambda (o) (eq "AcDbHatch" (vla-get-ObjectName o)))) L))
  15.             ); and
  16.             L
  17.           ); if
  18.         ); lambda
  19.         (cadr (ssgetfirst))
  20.       )
  21.     ); setq L
  22.     (
  23.       (lambda ( L / nSS )
  24.         (setq nSS (ssadd))
  25.         (foreach o L
  26.           (ssadd (vlax-vla-object->ename o) nSS)
  27.         ); foreach
  28.         (sssetfirst nil nil)
  29.         (sssetfirst nil nSS)
  30.       ); lambda
  31.       L
  32.     )
  33.   ); and
  34. ); defun  
  35.  
  36. (vlr-Miscellaneous-Reactor "AvoidHatches" '((:VLR-PickFirstModified . AvoidHatches:CB)))


But I am aware that my callback function might not be the faster way.

Can you come up with some alternatives that would be better? - to select anything else but the "HATCH" entities from the implied selection.

Title: Re: Avoid Hatches Sel - Reactor
Post by: Marc'Antonio Alessi on March 10, 2020, 06:33:59 AM
I don't know if I understand the question correctly ... perhaps the easiest way is the fastest:
Code: [Select]
(setq NewSSt (ssadd))
(repeat (setq i (sslength SS))
  (or
    (= "HATCH" (cdr (assoc 0 (entget (setq EntNam (ssname SS (setq i (1- i))))))))
    (setq NewSSt (ssadd EntNam))
  )
)
Title: Re: Avoid Hatches Sel - Reactor
Post by: VovKa on March 10, 2020, 07:25:53 AM
Currently I've got this working -
you've noticed that your function is 'recursive'?
the purpose of you filtering is unclear to me
why don't you want to use (ssget "_I" (list (cons 0 "~HATCH"))) ?
Title: Re: Avoid Hatches Sel - Reactor
Post by: Lee Mac on March 10, 2020, 09:08:49 AM
Changing the pickfirst selection within a function evaluated when the pickfirst selection is changed is never a good idea  :evil:
Title: Re: Avoid Hatches Sel - Reactor
Post by: roy_043 on March 10, 2020, 10:08:08 AM
Also consider that a selection set can contain sub-entities.
Title: Re: Avoid Hatches Sel - Reactor
Post by: Grrr1337 on March 15, 2020, 04:27:04 PM

Currently I've got this working -
you've noticed that your function is 'recursive'?
the purpose of you filtering is unclear to me
why don't you want to use (ssget "_I" (list (cons 0 "~HATCH"))) ?

Hi,
The point is while constantly selecting to filter out the hatch objects - the key is in lines 13. and 14.
"Recursion" stops when no acDbHatch objects are contained within the current selection.
My question was is if I could avoid the SS iteration in the 1st place - my callback function seems to be clumsy.



I don't know if I understand the question correctly ... perhaps the easiest way is the fastest:
Code: [Select]
(setq NewSSt (ssadd))
(repeat (setq i (sslength SS))
  (or
    (= "HATCH" (cdr (assoc 0 (entget (setq EntNam (ssname SS (setq i (1- i))))))))
    (setq NewSSt (ssadd EntNam))
  )
)

Thanks! I've got used with these lists that I've forgot I could just rebuilt the new SS within the iteration of the original SS.  :uglystupid2:
Title: Re: Avoid Hatches Sel - Reactor
Post by: Marc'Antonio Alessi on March 16, 2020, 04:24:19 AM
Thanks! I've got used with these lists that I've forgot I could just rebuilt the new SS within the iteration of the original SS.  :uglystupid2:
Well come on is not really a big flaw!    8-)             (Google Transl.)