Visual LISP, AutoLISP and General Customization
cancel
Showing results for 
Show  only  | Search instead for 
Did you mean: 

list of all blocks in a drawing

17 REPLIES 17
Reply
Message 1 of 18
pdn
Advocate
58237 Views, 17 Replies

list of all blocks in a drawing

Hello
probably very easy for the guru's
I'm trying to get a list of ALL blocks in a drawing (including all nested ones)
I tried, for example, (setq blist (acet-table-name-list (list "block" 1 4 16)))
but this gives me just one entry for a specific block while it is inserted several times
I need an entry for every single time a block is inserted, even if it is nested

Thanks in advance
Patrick
17 REPLIES 17
Message 2 of 18
Anonymous
in reply to: pdn

(setq ss (ssget "x" (list (cons 0 "INSERT"))))

and loop this SS



pdn@cadservice.be schreef:
> Hello
> probably very easy for the guru's
> I'm trying to get a list of ALL blocks in a drawing (including all
> nested ones)
> I tried, for example, (setq blist (acet-table-name-list (list "block" 1
> 4 16)))
> but this gives me just one entry for a specific block while it is
> inserted several times
> I need an entry for every single time a block is inserted, even if it is
> nested
>
> Thanks in advance
> Patrick
Message 3 of 18
pdn
Advocate
in reply to: pdn

Thanks
already tried this but this method does not list the nested blocks
For reasons to long to explain here, the whole drawing is already one single block with tents of "sub" and "sub sub" blocks
this method returns 1 for ss (the top level block)

Regards
Patrick
Message 4 of 18
Anonymous
in reply to: pdn

Best advice I can give you is to learn to use the search function for this forum.
Any search using "nested blocks" brings up a treasure trove of posts and solutions on the subject.

Here's some of them:

http://discussion.autodesk.com/forums/thread.jspa?messageID=6208304묰
http://discussion.autodesk.com/forums/thread.jspa?messageID=1137580宬
http://discussion.autodesk.com/forums/thread.jspa?messageID=1175198
http://discussion.autodesk.com/forums/thread.jspa?messageID=1208274濒


HTH

Bill
Message 5 of 18
Anonymous
in reply to: pdn



this is not easy...

You have to get a list of all blocks inserted in the drawing

Get a list of all block names in block table


check if the block has blocks inside
check if block name from table is
inserted in drawing or is part of another block

 

the hard part is getting the number of times a block is inserted -

BlockA is a circle

BlockB is a square with BlockA inside

BlockC is a Triangle with BlockB inside (also containing BlockA)

 

If you have inserted in the drawing only 3 blocks (1 BlockA, 1 BlockB and 1
BlockC) is total ??



BlockA = 1

BlockB = 1

BlockC = 1

or
BlockA = 3

BlockB = 2

BlockC = 1

 

 

 

<pdn@cadservice.be>
wrote in message
href="news:6353629@discussion.autodesk.com">news:6353629@discussion.autodesk.com
...


style="PADDING-RIGHT: 0px; PADDING-LEFT: 5px; MARGIN-LEFT: 5px; BORDER-LEFT: #000000 2px solid; MARGIN-RIGHT: 0px">Hello
probably
very easy for the guru's
I'm trying to get a list of ALL blocks in a
drawing (including all nested ones)
I tried, for example, (setq blist
(acet-table-name-list (list "block" 1 4 16)))
but this gives me just one
entry for a specific block while it is inserted several times
I need an
entry for every single time a block is inserted, even if it is
nested

Thanks in advance
Patrick
Message 6 of 18
wkmvrij
in reply to: pdn

I hope following is of interest. I would however like to ask the reason for this.. If you would want to use blocks for the implementation
of for instance a BOM you would run into the snag, that a scaling or mirroring of the block insert changes the nature of the object
that is represented by the block


;;; ===============================================================================
;;;Function (getblokken)
;;;Created by Willem van Rij, Brix Engineering
;;;Date Maart 2010
;;;Status under construction
;;; -------------------------------------------------------------------------------
;;;Action Analises Dwg for block definitions
;;;
;;;Return List of 2 lists of Structure:
;;; (
;;; ((("ReferencedBlockA") . NoOff)
;;; (("ReferencedBlockB") . NoOff)
;;; (("ReferencedNestedBlockC" ("BlockDefA" . NoOff")) . NoOff)
;;; )
;;; (("BlockDefA" ("NestedDefX" . NoOff))
;;; ("BlockDefB" ("NestedDefY" . NoOff))
;;; ("BlockDefC")
;;; ("BlockDefD")
;;; )
;;; )
;;;
;;;Remark uses (active-document). www.brix-engineering.com
;;; -------------------------------------------------------------------------------



(DEFUN getblokken (/ a n i blok bl_lst result ss tally)
(SETQ a (VLA-GET-BLOCKS (active-document))
n (VLA-GET-COUNT a)
i -1
)
;;Filter all non simple blocks out:
(WHILE (< (SETQ i (1+ i)) n)
(SETQ blok (VLA-ITEM a i))
(IF (AND (= (VLA-GET-ISXREF blok) :VLAX-FALSE)
(= (VLA-GET-ISLAYOUT blok) :VLAX-FALSE)
(NOT (WCMATCH (VLA-GET-NAME blok) "*`**,*|*"))
)
(PROGN ;;Each block to be reviewed for nested blocks:
(SETQ bl_lst (analiseblock blok))
(SETQ result (CONS (CONS (VLA-GET-NAME blok) bl_lst) result))

)
)
)
(MAPCAR ;; Find the inserted blocks:
'
(LAMBDA (x)
(SETQ ss (SSGET "X" (LIST '(0 . "INSERT") (CONS 2 (CAR x)))))
(IF ss
(SETQ tally (CONS (CONS x (SSLENGTH ss)) tally)
ss nil
)

)
)
result
)
;;;List of two lists: first atom is list of blocks actually referenced
;;; (dotted pairs: (Name . 'No. of entries') ),
;;; second atom is list of block definitions with their nested definitions:
(LIST tally result)
)
;;;-------------------------------------------------------------------------------------------

(DEFUN analiseblock (b / res n i item p a tally)
(SETQ n (VLA-GET-COUNT b)
i -1

)
(WHILE (< (SETQ i (1+ i)) n)
(SETQ item (VLA-ITEM b i)
)
(COND ((= (VLA-GET-OBJECTNAME item)
"AcDbBlockReference"
)
(IF (= 0 (SETQ p (LENGTH (MEMBER (VLA-GET-NAME item) res))))
(PROGN
(SETQ tally (CONS 1 tally))
(SETQ res (CONS (VLA-GET-NAME item) res))
)
(SETQ tally (SUBST (1+ (NTH (1- p) tally))
(NTH (1- p) tally)
tally
)
)

)
)
(T
nil
)
)
)
(IF res
(MAPCAR '(LAMBDA (x y)
(SETQ a (CONS (CONS x y) a))
)
res
tally
)
)
a
)
;;;-------------------------------------------------------------------------------------------
Message 7 of 18
pdn
Advocate
in reply to: pdn

Hello Willem

Thanks for the info but forgive my ignorance, how do I work with "active-document"
I have experience with "normal" list but not with the VLA environment
I get "undefined" on active document
The reason behind all this is that the files are converted ME10 files, one of the checks we need to do is to verify if the BOM generated from within ME10 isthe same in the resulting acad file

Thanks in advance
Patrick
Message 8 of 18
wkmvrij
in reply to: pdn

(active-document) is a simple LSP routine that will return It is available from www.brix-engineering.com. For your convinience listed here:

(VL-LOAD-COM)
(SETQ *acad-object* nil) ; Initialize global variable
(DEFUN acad-object ()
(COND (*acad-object*) ; Return the cached object
(T
(SETQ *acad-object* (VLAX-GET-ACAD-OBJECT))
)
)

)

(SETQ *active-document* nil) ; Initialize global variable
(DEFUN active-document ()
(COND (*active-document*) ; Return the cached object
(T
(SETQ *active-document* (VLA-GET-ACTIVEDOCUMENT (acad-object)))
)
)

)

(SETQ *model-space* nil) ; Initialize global variable
(DEFUN model-space ()
(COND (*model-space*) ; Return the cached object
(T
(SETQ *model-space* (VLA-GET-MODELSPACE (active-document)))
)
)

)
(SETQ *paper-space* nil) ; Initialize global variable
(DEFUN paper-space ()
(COND (*paper-space*) ; Return the cached object
(T
(SETQ *paper-space* (VLA-GET-PAPERSPACE (active-document)))
)
)

)
(SETQ *Preferences* nil)
(DEFUN preferences ()
(COND (*Preferences*)
(T
(SETQ *Preferences* (VLA-GET-PREFERENCES (acad-object)))
)
)
)
(SETQ *Selectionsets* nil)
(DEFUN Selection-sets ()
(COND (*Selectionsets*)
(T
(SETQ *Selectionsets*
(VLAX-GET-PROPERTY
(active-document)
'SelectionSets
) ;_ end of vlax-get-property
) ;_ end of setq
)
) ;_ end of cond
) ;_ end of defun

(SETQ *Utility* nil)
(DEFUN Utility ()
(COND (*Utility*)
(T
(SETQ *Utility*
(VLAX-GET-PROPERTY
(active-document)
'Utility
) ;_ end of vlax-get-property
) ;_ end of setq
)
) ;_ end of cond
) ;_ end of defun


Load this LSP before you run the block counter
Success!

W.K.M. van Rij
Brix Engineering
Message 9 of 18
wkmvrij
in reply to: pdn

Sorry, First line should read
(active-document) is a simple LSP routine that will return ....

Regards,
W.K.M. van Rij
Message 10 of 18
wkmvrij
in reply to: pdn

Damned....
(active-document) is a simple LSP routine that will return <VLA-OBJECT IAcadDocument -pointer->

Right this time??
Message 11 of 18
pdn
Advocate
in reply to: pdn

Thanks !
very much appreciated
Patrick
Message 12 of 18
Anonymous
in reply to: pdn

Do a simple Data Extraction.

 

https://knowledge.autodesk.com/support/autocad/learn-explore/caas/CloudHelp/cloudhelp/2016/ENU/AutoC...

 

At the end of the data extraction wizard, you have the option to insert a table with the quantity of each block into the drawing, and/or export into an Excel spreadsheet. If you've added Lookups into your blocks, you can choose to show that information int the table as well. I use this method for my planting plans. All of my plant blocks are named with their latin name created with lookups for Key, Common Name, and Form. Inside the Data Extraction Wizard, I can sort the plants by its name or any of the look ups I've created.

 

Message 13 of 18
PhilipKettering
in reply to: pdn

I would like to find the best way of taking blocks within blocks and having just one block

 

Message 14 of 18
wkmvrij
in reply to: PhilipKettering

I am not sure I understand your question. Could you please elaborate?

Message 15 of 18
PhilipKettering
in reply to: wkmvrij

After speaking with Volker from the Autodesk support, he recommended that I look at this Web page.

I am unsure about the nesting part and the previous comments. Nesting to me is a type of CAM

function, but I have a Visio document attached to this comment, which indicates what I have as an

example. What I want to achieve is to retain the test block with the geometry within a test block but

purge all blocks that would be children. There are sub blocks beneath the test block; I don’t know if

there’s a script to do that or not.

Message 16 of 18
wkmvrij
in reply to: PhilipKettering

Look at post 6 from this thread. The routine proposed there will give the list of all blocks in your drawing, formatted as described in the file header. When I answered to the question I forgot to include the helper function that followed later. Load the lot and run it on your drawing. 

 

A nested block is a block within a block, or a block within a block within a block. This nesting has nothing to do with economically placing parts on a sheet of steel for cutout.

 

You will have to decide what you want to do with the resulting list. A nested block definition may lose one of its definitions  but the removed definition will remain available as a single block. You may want to try the inline edit command to do so.  Further down the line of activities would be to PURGE the drawing, thus removing all block definitions that are not REFERENCED, nested or otherwise

Message 17 of 18
Anonymous
in reply to: Anonymous

awesome tip/tool.  Not sure if lists nested blocks.

Message 18 of 18
Anonymous
in reply to: pdn

Hi 

I solved this problem with this code "BECOUNT

you can see list of block's number that you select .

Can't find what you're looking for? Ask the community or share your knowledge.

Post to forums  

Autodesk Design & Make Report

”Boost