Author Topic: Counting blocks and listing there associated layer  (Read 2279 times)

0 Members and 1 Guest are viewing this topic.

TJAM51

  • Guest
Counting blocks and listing there associated layer
« on: February 08, 2005, 04:08:16 PM »
Does anyone have a routine that will count blocks (list their names) and also list the layer they are on?


Thanks

whdjr

  • Guest
Counting blocks and listing there associated layer
« Reply #1 on: February 08, 2005, 04:39:08 PM »
Here is one I have, but have never used:
Code: [Select]
; blk-lst.lsp - block list
;
; I have repeatedly had requests for listing attributes and their
; values, both constant and variable. So here is a set of different
; routines for doing so. Copy them, save them, read them, use them,
; distribute them, and have lots of fun!
;
; Jeremy Tammik, Autodesk AG, 91-05-23
; Modified & added c:cattl and c:attlst for Siro, 91-07-15
;
; Global: bnam
;
; Commands defined:
;
; c:blktbl lists the block table, showing what block definitions exist.
; c:blklst lists one block definition (all entities).
; c:cattl  lists all constant attributes in a block definition
; c:attlst lists all attributes in a block insertion, reading the
;          constant ones from the block definition and the variable ones
;          from the insertion entity.


(defun dxf (n ed) (cdr (assoc n ed)))


;==================================================================
; c:blktbl - block table list:
;
; List all the blocks defined in this drawing.

(defun c:blktbl (/ b)
    (while (setq b (tblnext "block" (not b)))
           (print b))
    (princ)
)


;==================================================================
; c:blklst - block list:
;
; List the definition of a user-selected block.

(defun c:blklst (/ nam b en)
    (if (not bnam) (setq bnam ""))
    (setq nam (getstring (strcat "Block name <" bnam ">: ")))
    (if (/= "" nam) (setq bnam nam))
    (if (setq b (tblsearch "block" bnam))
        (if (setq en (dxf -2 b))
            (progn
             (print (dxf 0 (entget en)))
             (while (setq en (entnext en))
                    (print (dxf 0 (entget en)))))
            (prompt (strcat "\nNo entities in block " bnam)))
        (prompt (strcat "\nBlock " bnam " not found.")))
    (princ)
)

;==================================================================
; pratt - print attribute ins point, tag, and value & incr counter:

(defun pratt (en type pcnt)
    (setq ed (entget en))
    (if (= type (dxf 0 ed))
        (if (or (/= "ATTDEF" (dxf 0 ed))       ; variable attribute: ATTRIB
                (/= 0 (logand 2 (dxf 70 ed)))) ; const: ATTDEF & const flag
            (progn
             (set pcnt (1+ (eval pcnt)))
             (print (dxf 10 ed))
             (prin1 (dxf 2 ed))
             (princ ": ")
             (prin1 (dxf 1 ed)))))
)

;==================================================================
; c:cattl - list constant attributes in block definition:
;
; List all the attributes of a user-selected block, both constant
; and variable:

(defun c:cattl (/ nam b en constcnt)
    (if (not bnam) (setq bnam ""))
    (setq nam (getstring (strcat "Block name <" bnam ">: "))
          constcnt 0)
    (if (/= "" nam) (setq bnam nam))
    (if (setq b (tblsearch "block" bnam))
        (if (setq en (dxf -2 b))
            (progn
             (pratt en "ATTDEF" 'constcnt)
             (while (setq en (entnext en))
                    (pratt en "ATTDEF" 'constcnt)))
            (prompt (strcat "\nNo entities in block " bnam)))
        (prompt (strcat "\nBlock " bnam " not found.")))
    (prompt (strcat "\nBlock " bnam " has " (itoa constcnt) " constant attributes."))
    (princ)
)

;==================================================================
; c:attlst - list all attributes of block definition and insertion:
;
; List all the attributes of a user-selected block, both constant
; and variable:

(defun c:attlst (/ nam b en1 en constcnt varcnt)
    (setq en (car (entsel)))
    (if (not en) (progn (prompt "\nNothing selected.")(quit)))
    (if (/= "INSERT" (dxf 0 (entget en))) (progn (prompt "\nNot a block.")(quit)))
    (setq bnam (dxf 2 (entget en))
          constcnt 0 varcnt 0 en1 en)

    ; list constant attributes:

    (if (setq b (tblsearch "block" bnam))
        (if (setq en (dxf -2 b))
            (progn
             (pratt en "ATTDEF" 'constcnt)
             (while (setq en (entnext en))
                    (pratt en "ATTDEF" 'constcnt)))
            (prompt (strcat "\nNo entities in block " bnam)))
        (prompt (strcat "\nBlock " bnam " not found.")))

    ; list variable attributes:

    (while (/= "SEQEND" (dxf 0 (entget (setq en1 (entnext en1)))))
           (pratt en1 "ATTRIB" 'varcnt))

    (prompt (strcat "\nBlock " bnam " has " (itoa constcnt) " constant attributes."))
    (prompt (strcat "\nBlock " bnam " has " (itoa varcnt) " variable attributes."))
    (princ)
)

You might want to change it a little to show layer name.  Also look at bcount in the expresstools for block counting.

hyposmurf

  • Guest
Counting blocks and listing there associated layer
« Reply #2 on: February 08, 2005, 05:00:45 PM »
Click here
.Maybe someone has a complete answer for you, but Fantomas seems to be going somewhere with this little program he is devising,Not sure how it will work when created,it counts blocks and will probably include the layers that the blocks are on.