Jump to content

COUNTING BLOCKS ZONE WISE(Please see attachmemnts for better understanding of my requirement.)


Recommended Posts

Posted (edited)

Please see attachmemnts for better understanding of my requirement.

Dear Helpers,

 

I have a lisp code that can count blocks in different layer. I need a modification like it can give blocks quantities in selected closed polylines which are in different layers.

I have two lisp codes now. Can anyone please help me to recode them.

 

Lisp code 1: (LIST THE TOTAL BLOCK COUNT WITH NAMES IN SELECTED AREA)

(defun C:BLKLST (/ BLKS CHK I J K L L1 N BNAME ENAME EDATA BLIST BNUM
                  BNAME1 BNAME2 TEMP1 TEMP2
                 )
  (princ "\nUse standard selection methods to ")
  (setq BLKS (ssget (list (cons 0 "INSERT"))))
  (setq L (sslength BLKS))
  (setq L (- L 1))
  (setq I 0)
  (setq BLIST (list "BLOCK NAMES"))
  (setq BNUM (list "INSTANCES"))
  (while (<= I L)
     (setq ENAME (ssname BLKS I))
     (setq EDATA (entget ENAME))
     (setq BNAME (assoc 2 EDATA))
     (setq BNAME (cdr BNAME))
     (setq CHK (member BNAME BLIST))
     (if (eq CHK NIL)
        (setq BLIST (cons BNAME BLIST))
     ) ;_ end of if
     (setq I (+ I 1))
  ) ; end while
  (setq L1 (length BLIST))
  (setq L1 (- L1 2))
  (setq J 0)
  (setq N 0)
  (setq K 0)
  (while (<= K L1)
     (setq N 0)
     (setq BNAME1 (nth K BLIST))
     (setq J 0)
     (while (<= J L)
        (setq ENAME (ssname BLKS J))
        (setq EDATA (entget ENAME))
        (setq BNAME2 (assoc 2 EDATA))
        (setq BNAME2 (cdr BNAME2))
        (if (eq BNAME1 BNAME2)
           (setq N (+ N 1))
        ) ;_ end of if
        (setq J (+ J 1))
     ) ; end while j
     (setq BNUM (cons N BNUM))
     (setq K (+ K 1))
  ) ; end while k
;;; Formatting
  (setq K 0)
  (princ)
  (command "TEXTSCR")
  (princ "\nBlock Name     Instance")
  (while (<= K L1)
     (setq TEMP1 (nth K BLIST))
     (setq TEMP2 (nth (- L1 K) BNUM))
     (princ "\n")
     (princ TEMP1)
     (princ "\t\t\t")
     (princ TEMP2)
     (setq K (+ K 1))
  ) ; end while k
  (princ "\n\nPress the <F2> key to hide the text screen after viewing results... ")
  (princ)
) ;_ end of defun

;(princ
;   "\n         Blocklst loaded...  Start command by typing   BLOCKLST "

;(princ)

 

Lisp code 2: (COUNT SELECTED BLOCKS LAYER WISE)

(defun c:LBC (/ en ss ctr bl the_list n)
(setq ss (ssget (list (cons 0 "INSERT")))
ctr (sslength ss)
)
(repeat ctr
(setq ctr (1- ctr)
en (entget (ssname ss ctr))
bl (strcat (cdr (assoc 2 en))"/"(cdr (assoc 8 en)))
)
(if (setq count (cdr (assoc bl the_list)))
(setq the_list (subst (cons bl (1+ count))(cons bl count) the_list))
(setq the_list (cons (cons bl 1) the_list))
)
)
(setq the_list (vl-sort the_list '(lambda (e1 e2)(< (car e1) (car e2)))))
(foreach n the_list
(princ (strcat "\nBlock/Layer: " (car n) ", count of :" (itoa (cdr n))))
)
)

 

Thanks,

T.Brahmanandam

 

BLOCK COUNT IN POLYLINE WISE.PNG

COUNTING BLOCKS WITH ZONE WISE.dwg

Edited by tnvsb
Posted (edited)

This is what I was looking for I am working on a data export of block info so your dwg is perfect for me to test, it crashed so that is good as I need real world test dwg's. I will do some more debugging and find out why, it makes a table of the results. I am looking though at commercial aspect say shareware cheap price etc.

 

I changed your blocks to have attributes and is sort of working, this shows zone 1 but you just select each zone and add to the 1 table you would just add a line in the table Zone number before add next zone the code keeps adding to the table or creates a new one if required. It should have seperated the different watts for a light type and totaled them will re debug code. 

ScreenShot138.jpg

Edited by BIGAL

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.
Note: Your post will require moderator approval before it will be visible.

Guest
Unfortunately, your content contains terms that we do not allow. Please edit your content to remove the highlighted words below.
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...