←  Wishlist

nanoCAD forum

»

BCOUNT - Block reporting tool

Johandre's Photo Johandre 01 Mar 2020

I would like to request we have a tool that reports how many blocks of any type there are.

For example: If I have many shapes and solids in my design, but all my electronics are blocks.
I want to be able to see how many of each part I have in my design, like MAINSRELAYS 10, ARDUINONANO 4, BTS7960 4, etc

In AutoCAD, I think this tool is called BCOUNT, but I don't mind how it works or what it's called.
If anybody has any VBA code that can do this, I would appreciate it too.
Quote

Kreator's Photo Kreator 01 Mar 2020

Hello.
What version of NC do you use?
Quote

pguimber's Photo pguimber 02 Mar 2020

Hello,
Nanocad 5 does not take LISP (as far as I know), but by exporting to DXF (* .DXF = text> * .CSV) this allows the content to be processed using a spreadsheet.
This requires taking into account the syntax of the DXF and developing a spreadsheet with BNBVAL and other functions, ... (or VBA) functions.

Otherwise see with the Pro versions of Nanocad for the LISP and the VBA.

Cordialy
Patrick
Quote

pguimber's Photo pguimber 02 Mar 2020

For example :
in http://ma83.free.fr/info/acadlisp.htm

Nbloc.lsp to load in Nanocad pro 11 (trial)

NBLOC.LSP . The NBLOC program displays the number of blocks that are contained in
the drawing. Information can be simply screen or saved
in a file which will have the extension "NBL". This file will be placed
in the same directory as the DWG file.

;NBLOC


(defun c:NBLOC ()

(initget "O N")
(setq choix (getkword "\nDésirez-vous créer un fichier contenant le nombre de bloc ? O/N: "))



(setq bl (list (cdr (assoc 2 (tblnext "block" T)))))

(setq nombl T)

(while (/= nombl nil)

(setq nombl (tblnext "block"))

(if (/= nombl nil)
(setq bl (append bl (list (cdr (assoc 2 nombl)))))
)

)

(setq compte 0)
(setq nb (length bl))

(setq f (open (strcat (getvar "dwgname") ".nbl") "w"))

(repeat nb

(setq ent (ssget "x" (list (cons 0 "INSERT") (cons 2 (nth compte bl)))))

(if (/= ent nil)
(setq nbloc (sslength ent))
(setq nbloc 0)
)

(princ (strcat "\n" (nth compte bl) " = " (itoa nbloc)))

(if (= choix "O")
(progn

(princ (nth compte bl) f)
(princ " = " f)
(princ nbloc f)
(princ "\n" f)

)
)


(setq compte (1+ compte))
)

(close f)

(if (= choix "O")
(princ (strcat "\nLe fichier contenant la liste des bloc se nomme: " (getvar "dwgname") ".NBL"))
)

(princ)

)

(princ "\n==> NBLOC")
(princ)
Quote

Johandre's Photo Johandre 03 Mar 2020

View PostKreator, on 01 March 2020 - 01:29 PM, said:

Hello.
What version of NC do you use?

Hi Keator, I'm using NanoCAD Pro x64bit v11.0.4761.8897 (build 4866).

View Postpguimber, on 02 March 2020 - 08:49 AM, said:

Hello,
Nanocad 5 does not take LISP (as far as I know), but by exporting to DXF (* .DXF = text> * .CSV) this allows the content to be processed using a spreadsheet.
This requires taking into account the syntax of the DXF and developing a spreadsheet with BNBVAL and other functions, ... (or VBA) functions.

Otherwise see with the Pro versions of Nanocad for the LISP and the VBA.

Cordialy
Patrick

Thanks Patrick, I will try that out. Pro 11 supports VBScript Jscript and LISP as far as I have found. I wrote a cell report tool that makes a CSV file for MicroStation in VBA because it was a lacking feature in v8 too.
If this doesn't work and I can't find any other solutions, I think I'll try that next.
Quote

Kreator's Photo Kreator 03 Mar 2020

So, there are three options to get what you need:
  • Use Select similar command - SELECTSIMILAR. You can find the button in the Properties window (Ctrl+1). Choose 1 block, then choose similar and you'll see the count. But that can only be used for same layer/color etc.
  • Use Selection window - SHOWTABQS. Here you can choose Blocks and choose the name of desired one to count. You'll see count of the blocks in the bottom of the window.
  • Use reports - tables, that collect objects by filter. Use Table - Report, name it, then press Select to add filter. Then choose Blocks and any other filters you need.
  • After that leave only Name field checked (you don't need other properties in the table just to count them). You'll get a table with all blocks in rows.
  • Now you need to combine and count them - get into the table (edit it). Group column A by name.
  • And the last - add column B. Name it "Count". Type =count() in the B column in the Report template section (right to the green cell). Now close and enjoy! You can save the table to your template or add it to tools pallete to use it anywhere later (no need to make it all every time).

Attached Files

Quote

Johandre's Photo Johandre 03 Mar 2020

That worked well enough Patrick, thank you!

I had already tried 4 other LISP files that didn't work at all.

It did not let me save the list due to an error I'm not smart enough to fix yet, but it still printed the results to the CommandLine. This will be enough to get me going.

I've edited the file to disable saving the list and translated it to English if anybody else needs it. This one is called NBLOCK (to distinguish itself from the original).

;NBLOCK
;English Adaptation of NBLOC without file-saving. - which doesn't work in nanoCAD 11 for some reason
(defun c:NBLOCK ()
(setq bl (list (cdr (assoc 2 (tblnext "block" T)))))
(setq nombl T)
(while (/= nombl nil)
(setq nombl (tblnext "block"))
(if (/= nombl nil)
(setq bl (append bl (list (cdr (assoc 2 nombl)))))
)
)
(setq compte 0)
(setq nb (length bl))
(repeat nb
(setq ent (ssget "x" (list (cons 0 "INSERT") (cons 2 (nth compte bl)))))
(if (/= ent nil)
(setq nblock (sslength ent))
(setq nblock 0)
)
(princ (strcat "\n" (nth compte bl) " = " (itoa nblock)))
(setq compte (1+ compte))
)
(princ)
)
(princ "\n==> NBLOCK")
(princ)
Quote

Johandre's Photo Johandre 03 Mar 2020

Thank you Kreator,
I've been doing it with selection tools one block at a time for now, but my files can have up to 50 different blocks and I can't always remember which ones. I need a solution that can find them all and list them very quickly for my work.
I will keep this in mind as a backup option.
Quote

Kreator's Photo Kreator 03 Mar 2020

View PostJohandre, on 03 March 2020 - 11:37 AM, said:

Thank you Kreator,
I need a solution that can find them all and list them very quickly
3rd solution fits ;) Paste the table once in your drawing - and you always can see the actual count of each block, it's updated immediately on any change. Up to you anyway. But if you use NC, get used to its tables - they are perfect and very useful.
https://cloud.mail.r.../2FTv/27NrVD1vo
Quote

Johandre's Photo Johandre 03 Mar 2020

View PostKreator, on 03 March 2020 - 12:34 PM, said:

3rd solution fits ;) Paste the table once in your drawing - and you always can see the actual count of each block, it's updated immediately on any change. Up to you anyway. But if you use NC, get used to its tables - they are perfect and very useful.
https://cloud.mail.r.../2FTv/27NrVD1vo

This is great! I didn't realise that it's a live-updating table! I copied it into my project as you suggested and am very happy with this. Thanks for making the effort of recording a video too.
I'll play with tables some more!
Quote

Kreator's Photo Kreator 03 Mar 2020

Welcome ;)
Yeah, read more about tables in NC - they are not just like boring tables, they are Excel-like and integrated into drawing database.
Quote

Johandre's Photo Johandre 04 Mar 2020

I've had a good play around with tables and really like it. There's some limitations on what formulas I can make though.

I'd like to be able to report the block's description and material too, since I think those are properties associated with blocks in nanoCAD, from what I can see in the Properties and Block menus, but those aren't options in the tables.
I was going to put the weight of every block in the description, then tally that too using formulas.
I tried making the Block Name look like this: "Block Name - Product Serial Number - Weight - Material - Brand" and run a string interpreter on it in the table, but I haven't found an option to split strings from tables.

I'd also like to be able to list nested blocks somehow - those seem to be excluded from the count in the table.
If we can somehow do these things, it would be a dream come true!
Quote

Kreator's Photo Kreator 04 Mar 2020

View PostJohandre, on 04 March 2020 - 01:01 AM, said:

I'd like to be able to report the block's description and material too, since I think those are properties associated with blocks in nanoCAD, from what I can see in the Properties and Block menus, but those aren't options in the tables.
I was going to put the weight of every block in the description, then tally that too using formulas.
I tried making the Block Name look like this: "Block Name - Product Serial Number - Weight - Material - Brand" and run a string interpreter on it in the table, but I haven't found an option to split strings from tables.
You can use attributes within blocks. Make Brand, SN, Weight, Material attributes, make them hidden if needed, and you'll be able to list them as usual properties in tables.

View PostJohandre, on 04 March 2020 - 01:01 AM, said:

I'd also like to be able to list nested blocks somehow - those seem to be excluded from the count in the table.
If we can somehow do these things, it would be a dream come true!
That's problem. A block is a single unit, no matter what it consists of. Maybe groups could be helpful? They are selected and moved like a single unit, but they remain being several units. But group itself can't be counted in table.
Quote

Johandre's Photo Johandre 04 Mar 2020

View PostKreator, on 04 March 2020 - 08:21 AM, said:

That's problem. A block is a single unit, no matter what it consists of. Maybe groups could be helpful? They are selected and moved like a single unit, but they remain being several units. But group itself can't be counted in table.
Ah, the same limitation as MicroStation. But still, it's good to be hitting the same limits as far more expensive software! :D
If only I could somehow insert groups as easily as blocks. Another problem for another day I think.

View PostKreator, on 04 March 2020 - 08:21 AM, said:

You can use attributes within blocks. Make Brand, SN, Weight, Material attributes, make them hidden if needed, and you'll be able to list them as usual properties in tables.
Oh, I didn't think of that. I've seen this tool before but have never tried it until now. I got it working! Thanks again!
Quote

MСAD's Photo MСAD 19 Sep 2021

View PostJohandre, on 04 March 2020 - 10:36 AM, said:

I didn't think of that. I've seen this tool before but have never tried it until now.
Possible use of groups in nanocad

Attached Files

Quote

MСAD's Photo MСAD 22 Sep 2021

View PostJohandre, on 03 March 2020 - 12:43 PM, said:

I didn't realise that it's a live-updating table! I

This example shows the capabilities of nanocad and the associativity of objects using the example of blocks
https://www.youtube....C2xb0Au&index=2
  • Automatic dynamic block counting
  • Grouping blocks on a specific layer
  • Automatic block numbering
  • Automatic control of the visibility parameter from tabular reports
  • And some more functions

Attached Files

Quote

Alx Synth's Photo Alx Synth 08 Nov 2022

I think is an absurd we need to use a Lisp Routine to do one of the most basic and elementary things in software.
Maybe the developer never imagined not even in his wildest dreams that we would need to count things after do the project?

PS: Dont feel sad NanoCAD, those incompetents from AutoCAD also didnt think about this.
Quote

MСAD's Photo MСAD 08 Nov 2022

View PostAlx Synth, on 08 November 2022 - 04:22 AM, said:

Maybe the developer never imagined not even in his wildest dreams that we would need to count things after do the project?
Maybe...
(24) ⚡ Dialogue for configuring the display of report properties - YouTube
What exactly do you want to count
Quote