Author Topic: Listing of All the Blocks in a Drawing  (Read 7889 times)

0 Members and 1 Guest are viewing this topic.

Bill Tillman

  • Guest
Listing of All the Blocks in a Drawing
« on: March 09, 2012, 10:19:02 AM »
...and by that I mean every dog-gone one of them, not just the ones inserted in the present model or paperspace...! I say this because after dozens and dozens of search results have been poured over, each of them touting "How To List ALL the Blocks in a Drawing File" I keep running into examples which will only look at what's inserted, or will only count what's inserted.

My drawing file currently has 170+ blocks in it and this list is going to get larger...not much but it will get larger. I have searched high and low and find a few bits which puts a list of the blocks in the text window like this:

Code: [Select]
(setq lst (acet-table-name-list (list "block" 1 4 16)))
But this only gives me the names of the blocks and leaves out the really important association #4 which has the detailed descriptions of each block, or as many of them in this file are missing descriptions and I want to find out which ones. I am having all kinds of difficulties with this due to my beginning status, but here is what I've tried to see through for an approach.

Code: [Select]
(setq ss1 (ssget "_X" '((0 . "INSERT"))))
By reading several other posts in this very forum, it is indicated that this will list all the blocks in the database. One fellow even uses the variable name BlocksInDataBase for his line of code. So I think great, that should allow me to create a selection list which I can then view. But this will only give me the name of the blocks which are presently inserted in the model or paperspace, and thus it only comes up with three items, which are three paperspace titleblocks I have for three different size layouts. I have found several other sources which say the same thing that is this code will collect "ALL" the blocks in the database when in reality it will only collect what's presently inserted.

What I can't seem to find is a method to get all the blocks, including that very important (4 . "Block_Description) (excuse me that's the only way I can think to describe it) included in my list. If only just to get this to dump to the text window as I can copy and paste it and use another tool to parse it.

I have also tried a slight manipulation of this:

Code: [Select]
(defun _tablenames ( table exclude / item result )
  (while (setq item (tblnext table (null item)))
    (if (zerop (logand (cdr (assoc 70 item)) exclude))
      (setq result (cons (cdr (assoc 2 item)) result))
    )
  )
  (reverse result)
)

This is from one of Lee-Mac's postings and I substituted (assoc 4 item) for (assoc 2 item) and at least got a bunch of the description fields to list. But something wasn't quite right because I ended up with a list which did not contain the same number of elements, they did not seem to be in the same order as when I made the first list with (assoc 2 item) and at least one of the fields had part of it's text at the head of the list and the remainder of it's text at the bottom of the list. I am very confused and information is just not as easy to find as one would think. Any advice would be appreciated.
« Last Edit: March 09, 2012, 10:27:16 AM by Bill Tillman »

alanjt

  • Needs a day job
  • Posts: 5352
  • Standby for witty remark...
Re: Listing of All the Blocks in a Drawing
« Reply #1 on: March 09, 2012, 10:46:11 AM »
FWIW, using VLA to step through the block table and create a list is a lot faster in drawings that have a lot of blocks....at least that's what I've encountered.
Civil 3D 2019 ~ Windohz 7 64bit
Dropbox

BlackBox

  • King Gator
  • Posts: 3770
Re: Listing of All the Blocks in a Drawing
« Reply #2 on: March 09, 2012, 11:20:36 AM »
FWIW, using VLA to step through the block table and create a list is a lot faster in drawings that have a lot of blocks....at least that's what I've encountered.

... *And* VLA can be used with ObjectDBX if the need arises to query drawings that aren't already open. A rarity I'm sure; just saying.
"How we think determines what we do, and what we do determines what we get."

alanjt

  • Needs a day job
  • Posts: 5352
  • Standby for witty remark...
Re: Listing of All the Blocks in a Drawing
« Reply #3 on: March 09, 2012, 11:24:40 AM »
FWIW, using VLA to step through the block table and create a list is a lot faster in drawings that have a lot of blocks....at least that's what I've encountered.

... *And* VLA can be used with ObjectDBX if the need arises to query drawings that aren't already open. A rarity I'm sure; just saying.
... *And* I have nothing further to add....except that...and that...and...
Civil 3D 2019 ~ Windohz 7 64bit
Dropbox

Bill Tillman

  • Guest
Re: Listing of All the Blocks in a Drawing
« Reply #4 on: March 09, 2012, 11:50:33 AM »
Well, it may not be pretty, but it's effective. I found just enough pieces here and there to put together something which will dump the list I'm after.

Code: [Select]
(defun c:GetBlks ()
(setq count 1)
(while (setq theblk (tblnext "BLOCK" (null theblk)))
    (setq blk1 (strcat (rtos count) "  " (cdr (assoc 2 theblk)) " - " (cdr (assoc 4 theblk))"\n"))
     (princ blk1)
     (setq count (+ 1 count))
  )
); end function

And if by speed you mean less than 1/2 second, this is fast enough for me. I only need it for collecting raw data to process elsewhere.

alanjt

  • Needs a day job
  • Posts: 5352
  • Standby for witty remark...
Re: Listing of All the Blocks in a Drawing
« Reply #5 on: March 09, 2012, 11:56:15 AM »
Well, it may not be pretty, but it's effective. I found just enough pieces here and there to put together something which will dump the list I'm after.

Code: [Select]
(defun c:GetBlks ()
(setq count 1)
(while (setq theblk (tblnext "BLOCK" (null theblk)))
    (setq blk1 (strcat (rtos count) "  " (cdr (assoc 2 theblk)) " - " (cdr (assoc 4 theblk))"\n"))
     (princ blk1)
     (setq count (+ 1 count))
  )
); end function

And if by speed you mean less than 1/2 second, this is fast enough for me. I only need it for collecting raw data to process elsewhere.
In our template (civil 3d forces all block definitions to exist in drawing), I could definitely see a difference b/w the two methods.
Civil 3D 2019 ~ Windohz 7 64bit
Dropbox

Bill Tillman

  • Guest
Re: Listing of All the Blocks in a Drawing
« Reply #6 on: March 09, 2012, 07:54:03 PM »
I finally got the vlax viewpoint on this. After reading some more at afralisp and digging some more on blocks, I came up with this:

Code: [Select]
(defun c:getblocks (/ thelist)
  (vl-load-com)
  (setq acadobject (vlax-get-Acad-Object))
  (setq activedocument (vla-get-activedocument acadobject))
  (setq BlockTable (vla-get-blocks activedocument))
  (vlax-for each BlockTable
    (setq thelist (cons (vla-get-Name each) thelist))
    (setq thelist (cons (vla-get-Comments each) thelist))
  )
  (if thelist
    (reverse thelist)
  )
) ;defun
(princ)

and then another method I found  on cadalyst.com but it still required some adjustment for what I needed:

Code: [Select]
(defun c:getblocks2 ( )
  (vl-load-com)
  (setq *blks*
       (vla-get-Blocks
(vla-get-activedocument
   (vlax-get-acad-object)
)
       )
)
(vlax-for item *blks*
  (if (eq (vla-get-IsLayout item) :vlax-false)
    (princ (strcat (vla-get-Name item)
   " -> "
   (vla-get-Comments item)
   "\n")
   )
  )
)
  )

My question though is why does the list need to be reversed. I'm still studying the output of these and my next step is to have it write a text file, but then I thought, hey why not just send it straight into Excel which is what I will do next.

Another annoying thing I found was that in searching for information on this topic..."vlisp list all blocks" found very little useful information. Only when I put in things like "vla-get-name" did the seaches start to yield results.
« Last Edit: March 09, 2012, 08:07:25 PM by Bill Tillman »

CAB

  • Global Moderator
  • Seagull
  • Posts: 10401
Re: Listing of All the Blocks in a Drawing
« Reply #7 on: March 10, 2012, 09:08:16 PM »
Quote
Another annoying thing I found was that in searching for information on this topic..."vlisp list all blocks" found very little useful information.

Quote
List blocks, nested blocks, xrefs into a structured list.
Topic: How to list all the blocks in a directory form?
http://www.theswamp.org/index.php?topic=28043.msg336481#msg336481  By MP
http://www.theswamp.org/index.php?topic=31524.msg370964#msg370964  by Tim Willey
http://www.theswamp.org/index.php?topic=29988.msg355655#msg355655  by Lee Mac
http://www.theswamp.org/index.php?topic=176.0  by Craig
http://www.theswamp.org/index.php?topic=3935.0 by whdjr


Google search:
"list  blocks" site:http://www.theswamp.org/index.php?board=2.0


I've reached the age where the happy hour is a nap. (°¿°)
Windows 10 core i7 4790k 4Ghz 32GB GTX 970
Please support this web site.