Author Topic: Get list of blocks that start with a number  (Read 1430 times)

0 Members and 1 Guest are viewing this topic.

Rabbit

  • Guest
Get list of blocks that start with a number
« on: December 21, 2012, 03:16:34 PM »
I'm trying to get a list of all blocks in a drawing that start with a number as the first element of the block name.  And to add to the difficulty, I need the effective names of the dynamic blocks.  For the life of me, I can't figure out how to do it.  I've looked at some advanced SSGET stuff and it only makes my head spin.

Basically, I'm looking for the same thing as the pulldown list in the INSERT dialog box, but only showing the blocks that start with a number.

I'll be taking this list and putting it into the Listbox routine that LeeMac wrote to allow the user to select a block to do things with.

Lee Mac

  • Seagull
  • Posts: 12929
  • London, England
Re: Get list of blocks that start with a number
« Reply #1 on: December 21, 2012, 06:09:34 PM »
Vanilla:
Code - Auto/Visual Lisp: [Select]
  1. (defun _blocklist ( / def lst )
  2.     (while (setq def (tblnext "BLOCK" (null def)))
  3.         (if
  4.             (and
  5.                 (zerop (logand 4 (cdr (assoc 70 def)))) ;; Not XRef
  6.                 (wcmatch (cdr (assoc 2 def)) "#*") ;; Name begins with number
  7.             )
  8.             (setq lst (cons (cdr (assoc 2 def)) lst))
  9.         )
  10.     )
  11.     (vl-sort lst '<)
  12. )

Visual:
Code - Auto/Visual Lisp: [Select]
  1. (defun _blocklist ( / lst )
  2.         (if
  3.             (and
  4.                 (= :vlax-false (vla-get-isxref blk))
  5.                 (wcmatch (vla-get-name blk) "#*")
  6.             )
  7.             (setq lst (cons (vla-get-name blk) lst))
  8.         )
  9.     )
  10.     (vl-sort lst '<)
  11. )

Rabbit

  • Guest
Re: Get list of blocks that start with a number
« Reply #2 on: January 02, 2013, 11:06:20 AM »
Lee, you are my hero, again.

I never thought of using wcmatch, and apparently I need to re-look at how wcmatch can be used.  I didn't know about using # to find a number.

Thanks again,
Rabbit.

Lee Mac

  • Seagull
  • Posts: 12929
  • London, England
Re: Get list of blocks that start with a number
« Reply #3 on: January 02, 2013, 11:09:58 AM »