Need LISP to do more help?

Discussion in 'AutoCAD' started by La-Z-CADtech, Jan 20, 2005.

  1. La-Z-CADtech

    La-Z-CADtech Guest

    i got this LISP off another site and it does relatively what i want it to do, the only thing is it only counts a single block rather then all blocks in the selection box.

    heres the code:

    (defun c:count-blocks (/ bname doc ent name pt1 pt2 ss tmp total)
    (if (and (or (setq ent (car (entsel "\nSelect a block to count: ")))
    (setq name (strcase (getstring "\nBlock name to find: ")))
    )
    (or name
    (setq name (cdr (assoc 2 (entget ent))))
    )
    (setq doc (vla-get-activedocument (vlax-get-acad-object)))
    (setq bname "")
    (setq pt1 (getpoint "\nFirst corner of Area to look: ")
    pt2 (getcorner pt1 "...other corner"))
    )
    (progn
    ;;;get all individual inserts
    (if (setq ss (ssget "w" pt1 pt2 (list '(0 . "INSERT")(cons 2 name))))
    (setq total (sslength ss))
    (setq total 0)
    )
    ;;;go through block defs
    (vlax-for blk (vla-get-blocks doc)
    (if (and (not (vl-string-search "`*" (setq bname (vla-get-name blk))))
    (not (vl-string-search "|" bname))
    (setq tmp 0)
    )
    (progn
    (vlax-for obj blk
    (if (and (eq (vla-get-objectname obj) "AcDbBlockReference")
    (eq (vla-get-name obj) name)
    )
    (setq tmp (1+ tmp))
    )
    )
    (if (and (not (zerop tmp))
    (setq ss (ssget "w" pt1 pt2 (list '(0 . "INSERT")(cons 2 bname))))
    )
    (setq total (+ total (* (sslength ss) tmp)))
    )
    )
    )
    )
    )
    )
    (if total
    (princ (strcat "\nTotal of " (itoa total) " " name " found."))
    )
    (princ)
    )

    it does the one thing that i absolutle need it to do and that is counting nested blocks no matter what the main block name is. But it would be nice to get it to count all the blocks that i need it to in the box that you make. So i need to give the lisp a list of blocks and have it find the blocks in that list using the selection box method. there are only 2 different blocks that are nested that i need it to find all the other blocks are just regular blocks, the reason i cant use bcount is because i have to go through a rather long list trying to find the ones i need.. so it would be great to get it to put a list just like bcount just with the blocks i need.

    can anyone help me out with this... thanks for any responses.

    oh and im running acad 2005...
     
    La-Z-CADtech, Jan 20, 2005
    #1
  2. La-Z-CADtech

    Matt W Guest

    Have you looked at BCOUNT??
    Comes with AutoCAD.
     
    Matt W, Jan 20, 2005
    #2
  3. La-Z-CADtech

    La-Z-CADtech Guest

    yes i have.. and it doesnt do what i need it to do seeing how it doesnt count the nested blocks.
     
    La-Z-CADtech, Jan 21, 2005
    #3
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.