×
INTELLIGENT WORK FORUMS
FOR ENGINEERING PROFESSIONALS

Log In

Come Join Us!

Are you an
Engineering professional?
Join Eng-Tips Forums!
  • Talk With Other Members
  • Be Notified Of Responses
    To Your Posts
  • Keyword Search
  • One-Click Access To Your
    Favorite Forums
  • Automated Signatures
    On Your Posts
  • Best Of All, It's Free!
  • Students Click Here

*Eng-Tips's functionality depends on members receiving e-mail. By joining you are opting in to receive e-mail.

Posting Guidelines

Promoting, selling, recruiting, coursework and thesis posting is forbidden.

Students Click Here

Jobs

Counting blocks

Counting blocks

Counting blocks

(OP)
ok well i have found 2 or 3 lisps that do this but dont exactly work the way i want them to i will post the one that i have now that actually counts for me now but what im looking for is one that gives me name of block then the layer that its on how many are on that layer and then if there are more on another layer list that layer and how many that is on it and continues on to the next one

the lisp i have now currently you give the block name it returns the entire drawing amount but nothing else or you can pick a block it will tell you the nam and how many there are in the drawing but like i said im looking for more something that i can just window in an area and it tell me the following

Block Name    Layer   Amount


if anyone wants it this is the block count routine i have

(defun c:cntblks ()
  (setvar "cmdecho" 0)
  (setq blkname (getstring "\nType block name or <enter> to pick: "))
  (if (= blkname "")
    (setq blkname (cdr (assoc 2 (entget (car (entsel))))))
  )
  (setq blockset (ssget "X" (list (cons 2 blkname))))
  (setq total (sslength blockset))
  (if (= total 1)
    (progn
      (princ "\n  ")(princ "\n  ")(princ "\n  ")(princ "\n  ")
      (textscr)
      (princ "\nThere is ")(princ total)(princ " block called ")(princ blkname)(princ"....")
      (princ "\n  ")(princ "\n  ")
    )
  )
  (if (> total 1)
    (progn
      (princ "\n  ")(princ "\n  ")
      (princ "\n  ")(princ "\n  ")
      (textscr)
      (princ "\nThere are ")(princ total)(princ " blocks called ")(princ blkname)(princ"....")
      (princ "\n  ")(princ "\n  ")
    )
  )
  (setvar "cmdecho" 1)
  (princ)
)

if everyone helps everybody the world will be a better place

RE: Counting blocks

Try this edited code...

(defun c:cntblks ()
  (setvar "cmdecho" 0)
  (setq blkname (getstring "\nType block name or <enter> to pick: "))
  (if (= blkname "")
    (setq blkname (cdr (assoc 2 (entget (car (entsel))))))
  )
;;; ADDED CODE HERE
  (setq layname (cdr (assoc 2 (tblnext "layer" t))))
  (textscr)
  (princ "\nBLOCK\tLAYER\tQUANITY")
  (while layname
  (setq blockset (ssget "X" (list (cons 2 blkname)(cons 8 layname))))
  (if blockset
   (setq total (sslength blockset))
   (setq total 0)
  )
;;; END ADDED CODE
;  (setq blockset (ssget "X" (list (cons 2 blkname))))
;  (setq total (sslength blockset))
;  (if (= total 1)
;    (progn
;      (princ "\n  ")(princ "\n  ")(princ "\n  ")(princ "\n  ")
;      (textscr)
;      (princ "\nThere is ")(princ total)(princ " block called ")(princ blkname)(princ"....")
;      (princ "\n  ")(princ "\n  ")
;    )
;  )
;  (if (> total 1)
;   (progn
;;; ADDED CODE HERE
   (if (> total 0)
    (progn
      (princ "\n")
      (princ blkname)
      (princ "\t")
      (princ layname)
      (princ "\t")
      (princ total)
;;; END ADDED CODE
;      (princ "\n  ")(princ "\n  ")
;      (princ "\n  ")(princ "\n  ")
;      (textscr)
;      (princ "\nThere are ")(princ total)(princ " blocks called ")(princ blkname)(princ"....")
;      (princ "\n  ")(princ "\n  ")
    )
  )
;;; ADDD CODE HERE
  (setq layname (cdr (assoc 2 (tblnext "layer"))))
  )
;;; END ADDED CODE
  (setvar "cmdecho" 1)
  (princ)
)


You can remove all of the commented lines to make the file smaller, I left them in so you could see the changes easily.

RE: Counting blocks

(OP)
ok that kinda worked but its still to where you either have to know the blocks name or be able to select the block how can i make it so that i just window in an area and any blocks with in that window are listed

also the columns ae not lining up where do i edit the routine to add space between  columns

if everyone helps everybody the world will be a better place

RE: Counting blocks

Forward your email address to lisper@bcinc.hypermart.net and I will send you something that should do the trick

RE: Counting blocks

See below:

 Autolisp to filter Blocks by rotation

The lisp routine I provided there:
-counts the blocks,
-gives their rotations in radians

For the whole drawing.

Remove the "X" from ssget statement and

it will do this for a selected area.

Hope this is useful.

Red Flag This Post

Please let us know here why this post is inappropriate. Reasons such as off-topic, duplicates, flames, illegal, vulgar, or students posting their homework.

Red Flag Submitted

Thank you for helping keep Eng-Tips Forums free from inappropriate posts.
The Eng-Tips staff will check this out and take appropriate action.

Reply To This Thread

Posting in the Eng-Tips forums is a member-only feature.

Click Here to join Eng-Tips and talk with other members!


Resources