AutoLISP - Select blocks in a row

eduardosforni
Participant
Participant

AutoLISP - Select blocks in a row

eduardosforni
Participant
Participant

Hi!

I needed a lisp routine that selects the blocks spaced in a row. For example, the routine selects the first block but does not select the second, it selects the third block .... and so on.

Does anyone know any routine that does this?


eduardosforni_0-1616627657485.png


Thank you!

0 Likes
Reply
Accepted solutions (1)
729 Views
3 Replies
  • Lisp
Replies (3)

Sea-Haven
Mentor
Mentor

This is very rough and is just a 1st go it will delete in a last to 1st order. needs more use involvement to clarify the direction etc of removal.

(defun c:test ( / ss num x y)
(setq ss (ssget '((0 . "INSERT"))))
(setq num (getint "\nEnter item number to remove 2 etc "))
(setq x 0 lst '())
(repeat (fix (/ (sslength ss) num))
(setq lst (cons (setq x (+ x num)) lst))
)
(foreach y lst
(command "erase" (ssname ss (- y 1)) "")
)
(princ)
)

, it needs a sort order if the blocks are not created in a sequence.

 

 

 

0 Likes

Kent1Cooper
Consultant
Consultant

Do you mean to select them for deletion, as @Sea-Haven assumes, or for some other reason [to put them on a different Layer, to replace them with a different Block, to ...]?

 

Are they independent Block insertions, and not an ARRAY object or MINSERT?

 

Do you propose to select a larger set and have a routine distinguish some of them from the others, or do you want a routine to find them for you?  If the latter, on what basis [same Block name or category of names, same Layer or category of Layers, same position in some axis's direction, etc.]?

 

As @Sea-Haven wondered, are they in creation order so that the distinction can be made on that basis, or must it be made on the basis of position only?

 

Etc....

Kent Cooper, AIA
0 Likes

Moshe-A
Mentor
Mentor
Accepted solution

@eduardosforni 

 

check this

 

Moshe

 

; select odd block
(defun c:SelOB (/ _sortpoints ss0 ss1 points i)

 (defun _sortpoints ()
  (mapcar
    '(lambda (ename)
      (cons ename (list (cdr (assoc '10 (entget ename)))))
     )
   (vl-remove-if 'listp (mapcar 'cadr (ssnamex ss0)))  
  ); mapcar
 )_sortpoints
  
 (if (setq ss0 (ssget '((0 . "insert")))) 
  (progn
   (setq i -1 ss1 (ssadd))
   (foreach item (vl-sort (_sortpoints) (function (lambda (a b) (< (caadr a) (caadr b)))))
    (if (= (rem (setq i (1+ i)) 2) 0)
     (ssadd (car item) ss1)
    )
   ); foreach

   (sssetfirst ss1 ss1)       
  ); progn
 ); if

 (princ) 
)

 

 

0 Likes