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

BCOUNT Feature no longer available in AutoCAD 2012

4 REPLIES 4
Reply
Message 1 of 5
lgabriel
1297 Views, 4 Replies

BCOUNT Feature no longer available in AutoCAD 2012

Our company moved to AutoCAD 2012 and discovered that the BCOUNT command (part of the Express Menu) no longer exists. Do not know if Autodesk replaced the command with something else, but half the engineering department came to me to solve it. So I wrote the following lisp program, which duplicates the BCOUNT function. I am posting it for anyone else who wants to use it. Only bug that occurs if the name of any block name is longer than 35 characters.

 

If this is an issue, change the repeat argument in the autotab function from 35 to whatever you need.

 

I learned a lot from this web site and I figure its good to give back.

 

;bcount.lsp l. gabriel 03.22.13
;
;object: to display block names and quantity found within a window area
;
(defun autotab (a)
   (setq tmpstr "")
   (setq l (strlen a))
   (repeat (- 35 l)
   (setq tmpstr (strcat "." tmpstr))
   (setq tmpstr tmpstr)
   )
)
;
(defun echooff ()
  (setq oldecho (getvar "CMDECHO"))
  (setq oldblip (getvar "BLIPMODE"))
  (setq oldosm (getvar "OSMODE"))
  (setvar "CMDECHO" 0)
  (setvar "BLIPMODE" 0)
  (setvar "OSMODE" 0)
  (setq olderror_echo *ERROR*)
  (terpri)
  (defun *ERROR* (msg)
    (princ " \n")
    (princ msg)
    (echoon)
  )
)
;
(defun echoon ()
  (setvar "CMDECHO" oldecho)
  (setvar "BLIPMODE" oldblip)
  (setvar "OSMODE" oldosm)
  (setq *ERROR* olderror_echo)
  (princ)
)
;main program
(defun c:bcount()
   (echooff)
   (setq pt1 (getpoint "\nSelect corner of window: "))
   (setq pt2 (getcorner pt1 "\nSelect opposite corner: "))
   (setq ss (ssget "W" pt1 pt2 '((0 . "INSERT"))))
   (setq blocklist (list nil))
   (setq idx 0)
;create block list  
   (repeat (sslength ss)
      (setq blocklist (append (list(cdr(assoc 2 (entget (ssname ss idx))))) blocklist))
      (setq idx (+ idx 1))  
   )
   (setq blocklist (vl-sort blocklist '<))
   (setq idx 1)
   (setq blkcnt 0)
   (setq lastblkname "")
   (textscr)
;Print Block List on screen
   (princ "\n\nBLOCK COUNT Version 1.0 LG\n")
   (princ "--------------------------------------\n")
   (repeat (- (length blocklist) 1)
      (setq blkname (nth idx blocklist))
   (if (OR(= blkname lastblkname)(= lastblkname ""))
      (progn
     (setq blkcnt (+ blkcnt 1))
   )
   (progn
     (princ (strcat lastblkname (autotab lastblkname) (itoa blkcnt) "\n"))
     (setq blkcnt 1)
   )
   )
   (setq lastblkname blkname)
   (setq idx (+ idx 1))
   )
   (princ (strcat lastblkname (autotab lastblkname) (itoa blkcnt) "\n"))
   (echoon)
)

4 REPLIES 4
Message 2 of 5
hmsilva
in reply to: lgabriel

lgabriel,

first of all, many thanks for sharing your routine, and just a simple opinion, was useful for the proper functioning of your routine, if you use an "if" for the

 

(setq ss (ssget "W"...

 

because if there is no "INSERT" in the selection, your code will give an error and you will receive this error message

 

"bad argument type: lselsetp nil"

 

hope that helps

Henrique

EESignature

Message 3 of 5
lgabriel
in reply to: lgabriel

Thank you for the suggestion. Makes the program full proof. Although you would not use BCOUNT unless you knew there blocks in the drawing, a user could window incorrectly, or try to use the program to test if any blocks existed in the drawing

 

Revised code

 

;bcount.lsp l. gabriel 03.22.13
;
;object: to display block names and quantity found within a window area
;
(defun autotab (a)
   (setq tmpstr "")
   (setq l (strlen a))
   (repeat (- 35 l)
   (setq tmpstr (strcat "." tmpstr))
   (setq tmpstr tmpstr)
   )
)
;
(defun echooff ()
  (setq oldecho (getvar "CMDECHO"))
  (setq oldblip (getvar "BLIPMODE"))
  (setq oldosm (getvar "OSMODE"))
  (setvar "CMDECHO" 0)
  (setvar "BLIPMODE" 0)
  (setvar "OSMODE" 0)
  (setq olderror_echo *ERROR*)
  (terpri)
  (defun *ERROR* (msg)
    (princ " \n")
    (princ msg)
    (echoon)
  )
)
;
(defun echoon ()
  (setvar "CMDECHO" oldecho)
  (setvar "BLIPMODE" oldblip)
  (setvar "OSMODE" oldosm)
  (setq *ERROR* olderror_echo)
  (princ)
)
;main program
(defun c:bcount()
   (echooff)
   (setq pt1 (getpoint "\nSelect corner of window: "))
   (setq pt2 (getcorner pt1 "\nSelect opposite corner: "))
;Create selection set of Blocks. If no blocks are found, display message box indicating "No blocks were found"
   (if (/= (setq ss (ssget "W" pt1 pt2 '((0 . "INSERT")))) nil)
      (progn
         (setq blocklist (list nil))
         (setq idx 0)
;create block list  
         (repeat (sslength ss)
            (setq blocklist (append (list(cdr(assoc 2 (entget (ssname ss idx))))) blocklist))
            (setq idx (+ idx 1))  
         )
         (setq blocklist (vl-sort blocklist '<))
         (setq idx 1)
         (setq blkcnt 0)
         (setq lastblkname "")
         (textscr)
;Print Block List on screen
         (princ "\n\nBLOCK COUNT Version 1.0 LG\n")
         (princ "--------------------------------------\n")
         (repeat (- (length blocklist) 1)
            (setq blkname (nth idx blocklist))
         (if (OR(= blkname lastblkname)(= lastblkname ""))
            (progn
        (setq blkcnt (+ blkcnt 1))
     )
     (progn
        (princ (strcat lastblkname (autotab lastblkname) (itoa blkcnt) "\n"))
        (setq blkcnt 1)
     )
        )
        (setq lastblkname blkname)
        (setq idx (+ idx 1))
        )
        (princ (strcat lastblkname (autotab lastblkname) (itoa blkcnt) "\n"))
      )
      (alert "No blocks were found within the selection window")
   )
   (echoon)
)

Message 4 of 5
hmsilva
in reply to: lgabriel

lgabriel,

I tested the code with blocks, and the code responded as expected, but as mean test, I forced the situation where the user does not select anything, that is a situation that can happen...

Do not get me wrong, your code is very good, and the first thing I did was thank you for sharing with us your code, I was just trying to contribute to make it a little better...

 

Cheers

Henrique

EESignature

Message 5 of 5
lgabriel
in reply to: hmsilva

No offense taken. Always room for improvement. Thanks fo the tip

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

Post to forums  

Autodesk Design & Make Report

”Boost