Jump to content

Getting a Block Count in a attributed Field


Recommended Posts

Posted

Hey ,

 

Im having trouble finding a option to get a field to display a count of a specific block. I need this info so i can put it into a data extraction. Any help would be much appreciated.

 

Thanks

Joey G

Posted

Hi,

It is not possible to have a field referenced to a number of any objects and blocks included.

Posted

tharwat ... is there anyway to modify this code to look into a nested block to pull a count out as well.

 

(defun c:recount (/ block_list cnt env_name)
(setq block_list
(list
(cons '2 "Shelf_Pin")
)
)
(foreach i block_list
(if
(setq ss (ssget "X" (list '(0 . "INSERT") i)))

(progn
(setq
cnt (itoa (sslength ss))
env_name (strcat "" (cdr i))
)
(setenv env_name cnt)
(princ (strcat "\nSet " env_name " to " cnt))
)

(progn
(setq
cnt "0"
env_name (strcat "" (cdr i))
)
(setenv env_name cnt)
(princ (strcat "\nSet " env_name " to " cnt))
)

)
)
(command "_REGEN") ;_refreshes field values
(princ)
)

Posted

I started with code by lee-mac, this is not perfect but worked for my test a block of the same block 5 times. If you have multiple name blocks then complexity level is way higher. Yes it needs some error trapping but a start.

 

;  get entities code by lee-mac
(defun GetBlockEntities  (Blk / tStr)
(if (tblsearch "BLOCK" Blk)
(GetObj (tblobjname "BLOCK" Blk))))

(defun GetObj  (bObj)
(if (setq bObj (entnext bObj))
(cons bObj (GetObj bObj))))

; Then pick a block to get block name 
(setq obj (vlax-ename->vla-object (car (entsel "\nPick block object"))))
(setq bname (vla-get-name obj))

(setq blks (GetBlockEntities bname))
(setq tot 0)
(repeat (setq x (length blks))
(setq bobj (vlax-ename->vla-object  (nth (setq x (- x 1)) blks)))
(if (= (vla-get-objectname bobj)  "AcDbBlockReference")
(progn
(vla-get-effectivename bobj)
(setq tot (+ tot 1))
)
)
)
(alert (strcat "Blocks found " (rtos tot 2 0) "\nCalled " (vla-get-effectivename bobj)))

Posted

The code I posted above was linked w/ a Diesel expression to updated a field that would in turn update the data extraction table. The only thing is that it didnt look into nested block for the specific block i was needing to count. I found code from LeeMac which works great but I cant figure out how to get the info output into the field and have it update the data extraction like before .. but here is the code. Im just looking for a specific block and have it automatically update the field like it did before. Thanks for the help

 

(defun c:nest (/ str lst tdef)
(while
(progn
(setq str (getstring t "\nSpecify Block Name <All> :"))
(cond ((eq "" str)
(while (setq tdef (tblnext "BLOCK" (null tdef)))
(setq lst (cons (cdr (assoc 2 tdef)) lst))) nil)
((and (snvalid str)
(tblsearch "block" str))
(setq lst (list str)) nil)
(t (princ "\n** Block not Found **")))))

(setq mstr (+ 5 (apply 'max (mapcar 'strlen lst)))) 
(princ (strcat (Pad "\n Block" 32 mstr) "| Count"))
(princ (strcat (Pad "\n " 45 mstr) (Pad "|" 45 10)))

(foreach x lst
(setq i (Blkcount x))
(princ
(strcat
(Pad (strcat "\n " x) 46 mstr)
(Pad "|" 46 (- 10 (strlen (itoa i)))) (itoa i)))) 

(princ))

(defun Pad (Str Chc Len)
(while (< (strlen Str) Len)
(setq Str (strcat Str (chr Chc))))
Str)

Posted

Anyone have some input which way to go w/ this ? ... any help would be very much appreciated

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...