LISp routine for selecting dynamic blocks

LISp routine for selecting dynamic blocks

Anonymous
Not applicable
2,154 Views
2 Replies
Message 1 of 3

LISp routine for selecting dynamic blocks

Anonymous
Not applicable

Hey guys, i have this lisp routine (not written by me) that select block by its names where i can put block name in command line, i need tweaking for it to work on dynamic blocks as well. 

 (defun C:SELBLKN ( / e ss) ; by name
(setq e (getstring T "\nType block name(s) to select (comma-delimited list or wildcards): "))
(if (> e "") (setq ss (ssget "_X" (list (cons 2 e)(cons 0 "INSERT")))))
(if (zerop (getvar "CMDACTIVE"))
  (progn (sssetfirst ss ss)(princ "Use 'P' for this selection set: ")(princ))
   ss
)
)
 
(princ "\nSELBLKN commands loaded.")(princ)

Regards
Amr Aly

 

0 Likes
Accepted solutions (1)
2,155 Views
2 Replies
Replies (2)
Message 2 of 3

ВeekeeCZ
Consultant
Consultant
Accepted solution

Here you go... try..

 

(vl-load-com)

(defun C:SELBLKN ( / e ss objs blk) ; by name
  (setq e (getstring T "\nType block name(s) to select (comma-delimited list or wildcards): ")
        objs (ssadd))
  (if (setq ss (ssget "_X" '((0 . "INSERT"))))
    (progn
      (repeat (setq i (sslength ss))
        (setq name (strcase (vla-get-effectivename (vlax-ename->vla-object (setq blk (ssname ss (setq i (1- i))))))))
        (if (wcmatch name (strcase e))
          (ssadd blk objs)))
    (if (zerop (getvar "CMDACTIVE"))
      (progn (sssetfirst nil objs)
        (princ "Use 'P' for this selection set: ")(princ))
      objs)))
  )

(princ "\nSELBLKN commands loaded.")(princ)
Message 3 of 3

Anonymous
Not applicable
Just tried it today and it works great, thanks a lot for the help.
0 Likes