Select All Occurences of a Dynamic Block and Bring to Front

Select All Occurences of a Dynamic Block and Bring to Front

Anonymous
Not applicable
829 Views
1 Reply
Message 1 of 2

Select All Occurences of a Dynamic Block and Bring to Front

Anonymous
Not applicable

I found this post and tried it but it is not working for me because I'm trying to select a dynamic block (https://forums.autodesk.com/t5/visual-lisp-autolisp-and-general/lisp-to-bring-blocks-to-front-with-d...).

 

Is there anyway to do this for dynamic blocks?

 

 

 

 

 

0 Likes
Accepted solutions (1)
830 Views
1 Reply
Reply (1)
Message 2 of 2

_gile
Consultant
Consultant
Accepted solution

Hi,

 

With dynamic blocks we have to select also all anonymous blocs ("`*U*") and then check if their "effective name" matches the searched block names.

 

Since AutoCAD 2012 we can use getpropertyvalue.

 

(defun c:demo (/ ss ent)
  (if (setq ss (ssget "_X" (list '(0 . "INSERT") (cons 2 "`*U*,90-13,CE-13,1161B")))) ; Block names
    (progn
      (repeat (setq i (sslength ss))
        (setq ent (ssname ss (setq i (1- i))))
        (if
          (not
            (wcmatch (getpropertyvalue (getpropertyvalue ent "BlockTableRecord") "Name")
                     "90-13,CE-13,1161B"            ; Block names
            )
          )
           (ssdel ent ss)
        )
      )
      (command "_.draworder" ss "" "_front")
    )
  )
  (princ)
)

 

For pior versions, we can search deeply in the DXF lists

 

(defun c:demo (/ ss i elst)
  (if (setq ss (ssget "_X" (list '(0 . "INSERT") (cons 2 "`*U*,90-13,CE-13,1161B")))) ; Block names
    (progn
      (repeat (setq i (sslength ss))
        (setq elst (entget (ssname ss (setq i (1- i)))))
        (if (and (wcmatch (cdr (assoc 2 elst)) "`*U*")
                 (not
                   (wcmatch (cdr
                              (assoc 2
                                     (entget
                                       (cdr
                                         (assoc 340
                                                (entget
                                                  (cdr
                                                    (assoc 360
                                                           (entget
                                                             (cdr
                                                               (assoc 360
                                                                      (entget
                                                                        (cdr
                                                                          (assoc 360 elst)
                                                                        )
                                                                      )
                                                               )
                                                             )
                                                           )
                                                    )
                                                  )
                                                )
                                         )
                                       )
                                     )
                              )
                            )
                            "90-13,CE-13,1161B"           ; Block names
                   )
                 )
            )
          (ssdel (cdr (assoc -1 elst)) ss)
        )
      )
      (command "_.draworder" ss "" "_front")
    )
  )
  (princ)
)


Gilles Chanteau
Programmation AutoCAD LISP/.NET
GileCAD
GitHub