Visual LISP, AutoLISP and General Customization

Reply
Distinguished Contributor
Posts: 104
Registered: ‎05-01-2003
Message 1 of 5 (452 Views)

BCOUNT Feature no longer available in AutoCAD 2012

452 Views, 4 Replies
03-23-2013 02:52 PM

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)
)

*Expert Elite*
Posts: 2,381
Registered: ‎12-17-2004
Message 2 of 5 (416 Views)

Re: BCOUNT Feature no longer available in AutoCAD 2012

03-24-2013 04:38 AM 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

Distinguished Contributor
Posts: 104
Registered: ‎05-01-2003
Message 3 of 5 (409 Views)

Re: BCOUNT Feature no longer available in AutoCAD 2012

03-24-2013 05:33 AM 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)
)

*Expert Elite*
Posts: 2,381
Registered: ‎12-17-2004
Message 4 of 5 (404 Views)

Re: BCOUNT Feature no longer available in AutoCAD 2012

03-24-2013 05:45 AM 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

Distinguished Contributor
Posts: 104
Registered: ‎05-01-2003
Message 5 of 5 (395 Views)

Re: BCOUNT Feature no longer available in AutoCAD 2012

03-24-2013 07:45 AM in reply to: hmsilva
No offense taken. Always room for improvement. Thanks fo the tip

You are not logged in.

Log into access your profile, ask and answer questions, share ideas and more. Haven't signed up yet? Register

Announcements
Welcome to the new Autodesk Community!
If this is your first visit, click here to get started and make the most of the Community. Let us know what you think of the new experience in the Community Feedback Forum.

Need installation help?

Start with some of our most frequented solutions to get help installing your software.

Ask the Community