Author Topic: Block select filter script selects undesired blocks  (Read 1322 times)

0 Members and 1 Guest are viewing this topic.

dubb

  • Swamp Rat
  • Posts: 1105
Block select filter script selects undesired blocks
« on: March 14, 2018, 12:20:32 PM »
This is not my script but I find it very useful. I need some tips on how to fix it.
The problem I'm having is the filtered selection is picking up blocks that aren't supposed to be a part of the selection set.

What the script does:
Selects only blocks that you specify.
First select a single block, then select a window or the entire drawing. Then the blocks will be selected.

Code: [Select]
;blockselect function
(defun bls (/ s blk bn opt )
(vl-load-com)
  (while (not
      (progn
        (initget "N")
        (setq blk (entsel "\nSelect Block/N for Block name:"))
        (cond
          ((null blk) (prompt "\n<<Null selection>>"))
          ((eq blk "N")
           (while (not
                    (and (Setq bn (getstring "\nEnter Block Name: "))
                         (tblsearch "Block" bn)
                    )
                  )
             (princ (Strcat "\n<< " bn " Invalid block name>>"))
             
           ) T
          )
          ((setq s (car blk))
           (if (eq (cdr (Assoc 0 (entget s))) "INSERT")
             (setq bn (vla-get-EffectiveName (vlax-ename->vla-object s)))
             (prompt "\n<<Invalid Object>>")
           )
          )
        )
      )
    )
  )
  (princ (Strcat "\nBlock Name Filter: " (Strcase BN)))
  (initget  "A W")
  (setq opt (cond ((getkword
                     (strcat "\n Choose option [Window/All] <Window>: ")
                   )
                  )
                  ("W")
            )
  )
  (sssetfirst nil(setq selection
         (ssget (if (eq opt "A") "_X" "_:L")
                (list '(0 . "insert")
                      (cons 2 (strcat bn ",`*U*"))
                                      )
         )
  ))
;(sssetfirst nil selection)
  (princ)
  )
(defun c:bls()
  (bls)
  (princ)
  )

ronjonp

  • Needs a day job
  • Posts: 7529
Re: Block select filter script selects undesired blocks
« Reply #1 on: March 14, 2018, 12:37:15 PM »
Quick look and this stands out: ",`*U*"
Code: [Select]
(list '(0 . "insert") (cons 2 (strcat bn ",`*U*")))

Windows 11 x64 - AutoCAD /C3D 2023

Custom Build PC

dubb

  • Swamp Rat
  • Posts: 1105
Re: Block select filter script selects undesired blocks
« Reply #2 on: March 14, 2018, 12:46:17 PM »
Would that be the block handle or anonymous name?

mjfarrell

  • Seagull
  • Posts: 14444
  • Every Student their own Lesson
Re: Block select filter script selects undesired blocks
« Reply #3 on: March 14, 2018, 12:52:25 PM »
ANON
Be your Best


Michael Farrell
http://primeservicesglobal.com/