Another idea might be to compare the area of the bounding box of each block. If you set the tolerance tight enough it should be fairly accurate I'd think.Oh.. this should be much faster I think. Probability of existence of different blocks with the same bounding box should be very low. I'll check both methods next week.
(defun blocks_select_same_bbox (fuzz / ent ss ss_lst size_x1 size_y1 size_x2 size_y2 ll1 ll2 ur1 ur2 new_ss)
(setq ent (ssname (ssget "_:S" (list '(0 . "INSERT") )) 0))
(vla-getboundingbox (vlax-ename->vla-object ent) 'll1 'ur1)
(setq size_x1 (- (car (vlax-safearray->list ur1)) (car (vlax-safearray->list ll1))) )
(setq size_y1 (- (cadr (vlax-safearray->list ur1)) (cadr (vlax-safearray->list ll1))) )
(setq ss (ssget "_X" (list '(0 . "INSERT") )) )
(setq ss_lst (mapcar 'cadr (ssnamex ss)))
(setq new_ss (ssadd))
(foreach blk ss_lst
(vla-getboundingbox (vlax-ename->vla-object blk) 'll2 'ur2)
(setq size_x2 (- (car (vlax-safearray->list ur2)) (car (vlax-safearray->list ll2))) )
(setq size_y2 (- (cadr (vlax-safearray->list ur2)) (cadr (vlax-safearray->list ll2))) )
(if (and (< (abs(- size_x1 size_x2)) fuzz) (< (abs(- size_y1 size_y2)) fuzz))
(setq new_ss (ssadd blk new_ss))
)
);foreach
(sssetfirst nil new_ss)
(vl-cmdf "_regen")
new_ss
)
That's pretty slick Lee :)
That's pretty slick Lee :)Yes it is.
Here's a rough draft to get you started:Awesome Lee, it's a big help to "get started" :-) Thanks!
Here's a rough draft to get you started:Awesome Lee, it's a big help to "get started" :-) Thanks!
LEE
Try to sellect thisblock (fist ar right) the lisp'll select 2 types
;;
;; Select Similar Blocks by name
;; Updated by 3dwannab on 2022.03.30.
;;
;; I updated this on the 2022.03.30 to use the SELECTSIMILAR command by setting
;; the SELECTSIMILARMODE to 128 which is to select similar by name.
;; Along with a filter for the selection of blocks, after this it's pretty simple.
;;
;; Initial code was here by Lee Mac: http://www.theswamp.org/index.php?topic=49667.msg548516#msg548516
;;
(defun c:QSBlocks_Similar ( / *error* acDoc def lst ss1 ss2 var_cmdecho var_osmode var_selectsimilarmode )
(princ "Filter select all similar Blocks by name :\n")
(defun *error* (errmsg)
(and acDoc (vla-EndUndoMark acDoc))
(and errmsg
(not (wcmatch (strcase errmsg) "*CANCEL*,*EXIT*"))
(princ (strcat "\n<< Error: " errmsg " >>\n"))
)
(setvar 'cmdecho var_cmdecho)
(setvar 'osmode var_osmode)
(setvar 'selectsimilarmode var_selectsimilarmode)
)
(setq acDoc (vla-get-ActiveDocument (vlax-get-acad-object)))
(or (vla-EndUndoMark acDoc) (vla-StartUndoMark acDoc))
(setq var_cmdecho (getvar 'cmdecho))
(setq var_osmode (getvar 'osmode))
(setq var_selectsimilarmode (getvar 'selectsimilarmode))
(setvar 'cmdecho 0)
(setvar 'osmode 0)
; Code by Lee Mac http://www.cadtutor.net/forum/showthread.php?92638-Simple-fix-%28LISP-noob%29-Syntax-problem&p=633824&viewfull=1#post633824
;; Iterate over the block table and compile a list of xref blocks to exclude
(while (setq def (tblnext "block" (not def)))
(if (= 4 (logand 4 (cdr (assoc 70 def))))
(setq lst (vl-list* "," (cdr (assoc 2 def)) lst))
)
)
;; Attempt to retrieve a selection of blocks (but not xrefs)
(setq ss1 (ssget (cons '(0 . "INSERT") (if lst (vl-list* '(-4 . "<NOT") (cons 2 (apply 'strcat (cdr lst))) '((-4 . "NOT>")))))))
;; Set selectsimilarmode to use the name of an object.
(setvar 'selectsimilarmode 128)
;; If ss1 one is valid then do this
(if ss1
(progn
(vl-cmdf "_.selectsimilar" ss1 "")
(setq ss2 (ssget)) ;; Create a new selection set for to zoom and reselect as the zoom objects will do this
(command "_.zoom" "_O" ss2 "")
(sssetfirst nil ss2)
(princ (strcat "\n: ------------------------------\n\t\t<<< "(itoa (sslength ss2)) (if (> (sslength ss2) 1) " <<< INSERTS objects" " <<< INSERT object") " selected\n: ------------------------------\n"))
)
(princ "\n: ------------------------------\n\t\t*** Nothing Selected ***\n: ------------------------------\n")
)
(*error* nil) (princ)
)