Counting blocks in a dwg

Discussion in 'AutoCAD' started by Xolo, Jun 14, 2004.

  1. Xolo

    Xolo Guest

    Hey all,

    I'm trying to write a very simple LISP to count the number of a certain
    block insertion in a drawing....and I'm not sure how to extract the block
    name from a selectionset.

    Anyone out there know how to do this?

    Thanks,

    Xolo
     
    Xolo, Jun 14, 2004
    #1
  2. Xolo

    Jeff Mishler Guest

    Since you know what the block name is you want to count, just use the filter
    on the selection set

    (setq bname "blockname")
    (setq ss (ssget "x" (list '(0 . "INSERT)(cons 2 bname))))
    (setq #blocks (sslength ss))

    HTH,
    Jeff
     
    Jeff Mishler, Jun 14, 2004
    #2
  3. Xolo

    Xolo Guest

    Jeff,

    That helped, but my quick LISP isn't finishing. Could you take a look at it
    and suggest why it's not finishing?

    Thanks again

    Xolo
    ------------------------------------

    ;;;-----------------------------------------------------------------------;
    ;;; June 13, 2004 WRITTEN BY THOMAS M. STORZUK EX12.lsp ;
    ;;;-----------------------------------------------------------------------;
    ;;; This program asks for a block name, and tells the user how ;
    ;;; many instances of that block occurs within the drawing ;
    ;;;-----------------------------------------------------------------------;
    (defun DTR (deg) (* pi (/ deg 180.0)))
    ;;;-----------------------------------------------------------------------;
    (defun C:EX12 (/ svce svom)
    (setq svce (getvar "cmdecho"))
    (setq svom (getvar "osmode"))
    (setvar "cmdecho" 0)
    (setvar "osmode" 0)

    (setq BLKN (getstring "\nEnter a block name: "))

    (setq SS1 (ssget "x" (list '(0 . "INSERT") (cons 2 BLKN))))
    (setq NUMB (sslength SS1))
    (if (not SS1)
    (princ "\nThere are no blocks in this drawing: ")
    (progn
    (princ "\nThere are ")
    (princ NUMB)
    (princ " blocks with the name ")
    (princ (rtos BLKN))
    (princ ".")
    )
    )

    (setvar "cmdecho" svce)
    (setvar "osmode" svom)
    (princ)
    )
    ;;;-----------------------------END OF THE FILE---------------------------;

    ------------------------------
     
    Xolo, Jun 14, 2004
    #3
  4. Xolo

    Xolo Guest

    Jeff,

    Sorry, but I figured it out myself.....thanks though.

    Xolo
     
    Xolo, Jun 14, 2004
    #4
  5. Xolo

    Jürg Menzi Guest

    Xolo

    Express Tools -> BCOUNT

    Cheers
     
    Jürg Menzi, Jun 14, 2004
    #5
Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments (here). After that, you can post your question and our members will help you out.