Author Topic: Counting Blocks  (Read 19766 times)

0 Members and 1 Guest are viewing this topic.

Luke

  • Guest
Re: Counting Blocks
« Reply #45 on: May 02, 2007, 09:52:45 AM »
No sweat.

Mark

  • Custom Title
  • Seagull
  • Posts: 28762
Re: Counting Blocks
« Reply #46 on: May 02, 2007, 10:42:56 AM »
Try this one Luke

Code: [Select]
(defun c:recount (/ block_list cnt env_name)

  ;; The intent of this app is to count the number of blocks inserted into
  ;; a given dwg and set environment variables based on the block name so
  ;; one can use the diesel expression '$(getenv, <name>)' in a table cell
  ;; to track the number of block insertitions therein
  ;;
  ;; Typical output
  ;;
  ;; Set BLOCK_COUNT_ELM to 6
  ;; Set BLOCK_COUNT_CITRUS to 5
  ;; Set BLOCK_COUNT_OAK to 11
  ;; Set BLOCK_COUNT_PALM to 5
  ;;
  ;; Given the above output you would use '$(getenv, BLOCK_COUNT_OAK)' in
  ;; your table cell
  ;;
  ;; version 2.0
  ;; Wed May 02, 2007
  ;; Mark S. Thomas ( mark@theswamp.org )

  ;
  ; list of blocks you wish to count
  ;
  (setq block_list
(list
  ;
  ; add a line for each block you wish to count
  ; the following are just samples
  ;
  (cons '2 "ELM")
  (cons '2 "CITRUS")
  (cons '2 "OAK")
  (cons '2 "PALM")
  )
)

  (foreach i block_list
   (setq ss (ssget "X" (list '(0 . "INSERT") i)))

   (if ss
     (progn
       (setq
;
; count the number of blocks inserted
; create the environment name, i.e. "BLOCK_COUNT_ELM"
;
cnt (itoa (sslength ss))
env_name (strcat "BLOCK_COUNT_" (cdr i))
)

       ; finally we set the environment variable
       (setenv env_name cnt)

       ; show the user what was set and how many blocks were counted
       (princ (strcat "\nSet " env_name " to " cnt))
       )
     ;; else if ss = nil then no blocks were found and
     ;; we set 'env_name' to zero
     (progn
       (setq
;
; create the environment name, i.e. "BLOCK_COUNT_ELM"
;
env_name (strcat "BLOCK_COUNT_" (cdr i))
)

       ; finally we set the environment variable to zero
       (setenv env_name "0")

       ; show the user what was set and how many blocks were counted
       (princ (strcat "\nSet " env_name " to 0"))
       )
     )
   )
  (princ)
  )
TheSwamp.org  (serving the CAD community since 2003)

Luke

  • Guest
Re: Counting Blocks
« Reply #47 on: May 02, 2007, 11:28:35 AM »
Mark,
Thank you.  That did it.

Luke

bdaiss

  • Guest
Re: Counting Blocks
« Reply #48 on: June 23, 2014, 03:55:08 PM »
I know this thread hasn't been posted in for a while but I'm curious if its possible to set the block counts to a specific window within a drawing and set it to recount the blocks every time you regen. This would basically function like the block count function in AutoField but with more control. My goal is to have the window be able to be adjusted like any polyline so that it doesn't have to be reset in the code every time. Its beyond my abilities in lisp and diesel. I saw this thread and thought it was worth a try to ask for help......

functions needed:
-select object for window and be able to edit the object after it is selected
-count objects and set them to a field using diesel or other ways if needed