Author Topic: Select dynamic block and normal block by name and pick  (Read 270 times)

0 Members and 1 Guest are viewing this topic.

PPETROS

  • Newt
  • Posts: 24
Select dynamic block and normal block by name and pick
« on: January 18, 2023, 05:59:46 AM »
Hello, everyone!

I am trying to adjust the following lisp in order to select (multiple) both blocks and dynamic blocks at once based on their name, by previewing the selection.
I am doing something wrong.
Can anyone help me by fixing the code?
Thank you in advance.

PPETROS

  • Newt
  • Posts: 24
Re: Select dynamic block and normal block by name and pick
« Reply #1 on: January 18, 2023, 06:40:46 AM »
;;THIS IS THE CODE
(defun C:sblks (/ e ss sss obj blk blkl) ; multiple
(setq blkl ""  sss (ssadd))
(while
(setq obj (vlax-ename->vla-object (Car (entsel))))
(setq e (vla-get-effectivename obj))
  (setq blkl (strcat blkl "," e))
  (princ (substr blkl 2))
 );while

(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 blkl)))
    (if (zerop (getvar "CMDACTIVE"))
      (progn (sssetfirst nil blkl)
        (princ "Use 'P' for this selection set: ")(princ))
      blkl)))
  )

mhupp

  • Bull Frog
  • Posts: 233
Re: Select dynamic block and normal block by name and pick
« Reply #2 on: January 18, 2023, 10:05:06 AM »
Don't think this will work on dynamic blocks since they are stored as anonymous blocks?

Code - Auto/Visual Lisp: [Select]
  1. (defun C:sblks (/ ss blklst) ; multiple
  2.   (prompt "\nSelect Block: ")
  3.   (setq blklst "")
  4.   (if (setq ss (ssget '((0 . "INSERT"))))
  5.     (foreach blk (vl-remove-if 'listp (mapcar 'cadr (ssnamex ss)))
  6.       (setq blklst (strcat (cdr (assoc 2 (entget blk))) "," blklst))
  7.     )
  8.   )
  9.   (if (setq ss (ssget "_X" (list '(0 . "INSERT") (cons 2 blklst))))
  10.     (sssetfirst nil ss)
  11.   )
  12.   (princ)
  13. )

PPETROS

  • Newt
  • Posts: 24
Re: Select dynamic block and normal block by name and pick
« Reply #3 on: January 18, 2023, 12:28:50 PM »
First of all, I would like to thank you very much for your help.
I tested your code and indeed it does not work with the dynamic block.
I need a lisp that selects both dynamic and normal blocks, by previewing the selection and adding them in a desired list.
Consider the name of blocks as the effectivename.
I really appreciate your effort.

mhupp

  • Bull Frog
  • Posts: 233
Re: Select dynamic block and normal block by name and pick
« Reply #4 on: January 18, 2023, 04:17:53 PM »
Code - Auto/Visual Lisp: [Select]
  1. (defun C:sblks (/ ss ss1 name lst) ; multiple
  2.   (prompt "\nSelect Block: ")
  3.   (setq ss (ssadd))
  4.   (if (setq ss1 (ssget '((0 . "INSERT"))))
  5.     (foreach blk (vl-remove-if 'listp (mapcar 'cadr (ssnamex ss1)))
  6.       (setq name (vla-get-effectivename (vlax-ename->vla-object blk)))
  7.       (if (not (member name lst))
  8.         (setq lst (cons name lst))
  9.       )
  10.     )
  11.   )
  12.   (if (setq ss1 (ssget "_X" (list '(0 . "INSERT"))))
  13.     (foreach blk (vl-remove-if 'listp (mapcar 'cadr (ssnamex ss1)))
  14.       (if (member (vla-get-effectivename (vlax-ename->vla-object blk)) lst)
  15.         (ssadd blk ss)
  16.       )
  17.     )
  18.   )
  19.   (sssetfirst nil ss)
  20.   (princ)
  21. )

PPETROS

  • Newt
  • Posts: 24
Re: Select dynamic block and normal block by name and pick
« Reply #5 on: January 19, 2023, 03:32:31 AM »
Mate, I have tested the lisp file and it works fine.
Very good work.
Thank you very much for your help.