Author Topic: BCOUNT -ALPHABETICAL  (Read 6826 times)

0 Members and 1 Guest are viewing this topic.

rkysela

  • Guest
BCOUNT -ALPHABETICAL
« on: May 07, 2009, 03:02:03 AM »
Hello, can anyone help me ? I use huge amount of different blocks in drawing and if I count them by BCOUNT the list displays at NON alphabetical order. Is there any way how to force AutoCad to display them at alphabetical order ???

It's Alive!

  • Retired
  • Needs a day job
  • Posts: 8722
  • AKA Daniel
Re: BCOUNT -ALPHABETICAL
« Reply #1 on: May 07, 2009, 07:27:02 AM »

Welcome to TheSwamp  :-)
I don’t know if you can change the behavior of the command, but this might be something that can be recreated in lisp

something like

Code: [Select]
(DEFUN C:MYBCOUNT ( / c i l p s sl v)
  (VL-LOAD-COM)
  (SETQ S (SSGET "X" '((0 . "INSERT")))
L '()
SL '()
P ""
  )
  (PRINC "\nBlock.........................Count")
  (PRINC "\n-----------------------------------")
 
  (IF S
    (PROGN
      (SETQ C 0)
     
      (WHILE (< C (SSLENGTH S))
(SETQ L (CONS (STRCASE(CDR (ASSOC 2 (ENTGET (SSNAME S C))))) L)
      C (1+ C)))
     
      (SETQ L (VL-SORT L '>))
     
      (FOREACH V L
(IF (NOT (VL-POSITION V SL))
  (SETQ SL (CONS (STRCASE V) SL))))
 
      (FOREACH V SL
(SETQ C 0)
(FOREACH I L
  (IF (= V I)
    (PROGN
      (SETQ C (1+ C)))))
     
(IF (> C 0)
  (PROGN
    (REPEAT (- 30 (STRLEN V))
      (SETQ P (STRCAT P ".")))
       (PRINC (STRCAT "\n" V P (ITOA C)))
                (SETQ P "")
   
  )
)
      )
    )
  )
  (PRINC)
)

Mark

  • Custom Title
  • Seagull
  • Posts: 28762
Re: BCOUNT -ALPHABETICAL
« Reply #2 on: May 07, 2009, 08:27:45 AM »
May or may not help but, you could use dataextraction and get a table of block names in alphabetical order.
TheSwamp.org  (serving the CAD community since 2003)

ronjonp

  • Needs a day job
  • Posts: 7529
Re: BCOUNT -ALPHABETICAL
« Reply #3 on: May 07, 2009, 11:11:25 AM »
Here's what I use. Works with modified dynamic blocks too  :-)

Code: [Select]
;;; AUTHOR
;;; Copyright© 2009 Ron Perez (ronperez  at  gmail  .  com)
;;;

(defun c:blockcount (/ blks lst maxstr names out ss str tmp total)
  (vl-load-com)
  (if (setq ss (ssget '((0 . "INSERT"))))
    (progn (setq ss    (mapcar 'vlax-ename->vla-object
                               (vl-remove-if 'listp (mapcar 'cadr (ssnamex ss)))
                       )
                 blks  (vla-get-blocks (vla-get-activedocument (vlax-get-acad-object)))
                 str   ""
                 total 0
           )
           (vlax-map-collection blks
                                '(lambda (x)
                                   (if (not (wcmatch (vla-get-name x) "`**,*|*"))
                                     (setq names (cons (vla-get-name x) names))
                                   )
                                 )
           )
           (setq maxstr (+ 3 (apply 'max (mapcar 'strlen names))))
           (foreach x (reverse (acad_strlsort names))
             (foreach y ss
               (if (= (vla-get-effectivename y) x)
                 (setq lst (cons y lst))
               )
             )
             (if lst
               (setq tmp   ""
                     str   (strcat "\n"
                                   x
                                   (repeat (- maxstr (strlen x)) (setq tmp (strcat "." tmp)))
                                   (itoa (length lst))
                           )
                     out   (cons str out)
                     total (+ (length lst) total)
                     lst   nil
                     tmp   ""
               )
             )
           )
           (princ "\n")
           (repeat (apply 'max (mapcar 'strlen out)) (princ "="))
           (princ (apply 'strcat out))
           (princ "\n")
           (repeat (apply 'max (mapcar 'strlen out)) (princ "="))
           (princ
             (strcat "\nTOTAL"
                     (repeat (- maxstr (strlen "TOTAL")) (setq tmp (strcat " " tmp)))
                     (itoa total)
             )
           )
    )
    (princ "\nNo blocks selected...")
  )
  (princ)
)

*bug fix: repeat in strcat returned nil when maxstrlen = blockname strlen
« Last Edit: May 22, 2009, 12:30:22 PM by ronjonp »

Windows 11 x64 - AutoCAD /C3D 2023

Custom Build PC

It's Alive!

  • Retired
  • Needs a day job
  • Posts: 8722
  • AKA Daniel
Re: BCOUNT -ALPHABETICAL
« Reply #4 on: May 07, 2009, 11:18:01 AM »
Yeah, but My dots are prettier   :lol:

ronjonp

  • Needs a day job
  • Posts: 7529
Re: BCOUNT -ALPHABETICAL
« Reply #5 on: May 07, 2009, 11:20:47 AM »
Very true  :-)

*now I have to make my dots pretty

Windows 11 x64 - AutoCAD /C3D 2023

Custom Build PC

It's Alive!

  • Retired
  • Needs a day job
  • Posts: 8722
  • AKA Daniel
Re: BCOUNT -ALPHABETICAL
« Reply #6 on: May 07, 2009, 11:22:30 AM »
Does mine not work with modified dynamic blocks? I don’t have any so I couldn’t test

ronjonp

  • Needs a day job
  • Posts: 7529
Re: BCOUNT -ALPHABETICAL
« Reply #7 on: May 07, 2009, 11:37:35 AM »
Does mine not work with modified dynamic blocks? I don’t have any so I couldn’t test

Daniel,

It picks them up as anonymous blocks (this is all the same block):

*U23..........................1
*U24..........................2
*U25..........................1

Windows 11 x64 - AutoCAD /C3D 2023

Custom Build PC

It's Alive!

  • Retired
  • Needs a day job
  • Posts: 8722
  • AKA Daniel
Re: BCOUNT -ALPHABETICAL
« Reply #8 on: May 07, 2009, 11:42:48 AM »
Oh ok, Thanks for the test! I better fix this  :-o

ronjonp

  • Needs a day job
  • Posts: 7529
Re: BCOUNT -ALPHABETICAL
« Reply #9 on: May 07, 2009, 12:11:49 PM »
Updated code above...prints prettier results  :lol:


Windows 11 x64 - AutoCAD /C3D 2023

Custom Build PC

It's Alive!

  • Retired
  • Needs a day job
  • Posts: 8722
  • AKA Daniel
Re: BCOUNT -ALPHABETICAL
« Reply #10 on: May 07, 2009, 07:03:35 PM »
Nice!  8-)

ronjonp

  • Needs a day job
  • Posts: 7529
Re: BCOUNT -ALPHABETICAL
« Reply #11 on: May 07, 2009, 11:38:47 PM »

Windows 11 x64 - AutoCAD /C3D 2023

Custom Build PC

stevesfr

  • Newt
  • Posts: 54
Re: BCOUNT -ALPHABETICAL
« Reply #12 on: May 21, 2009, 07:56:34 PM »
Updated code above...prints prettier results  :lol:



Works with vanilla blocks. Why it doesn't work with blocks having attributes?

steveo
ac2008 vanilla
Can't remember what I'm supposed to forget.

FengK

  • Guest
Re: BCOUNT -ALPHABETICAL
« Reply #13 on: May 22, 2009, 03:41:56 AM »

Works with vanilla blocks. Why it doesn't work with blocks having attributes?

steveo
ac2008 vanilla

that's odd, since all the code is doing is looping through selected blocks and count them by different effective name. it should not have anything to do with having attributes or not. try again or maybe post a sample drawing?

ronjonp

  • Needs a day job
  • Posts: 7529
Re: BCOUNT -ALPHABETICAL
« Reply #14 on: May 22, 2009, 11:32:21 AM »
Updated code above...prints prettier results  :lol:



Works with vanilla blocks. Why it doesn't work with blocks having attributes?

steveo
ac2008 vanilla

I just tested it and it worked for me??

Windows 11 x64 - AutoCAD /C3D 2023

Custom Build PC