JoeyG_77 Posted September 14, 2017 Posted September 14, 2017 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 Quote
Tharwat Posted September 14, 2017 Posted September 14, 2017 Hi, It is not possible to have a field referenced to a number of any objects and blocks included. Quote
JoeyG_77 Posted September 14, 2017 Author Posted September 14, 2017 I've seen people writing lisps and then using a custom field to apply the info from the lisp, but I cant figure out the connection between the 2. https://forums.autodesk.com/t5/autocad-for-mac-forum/linking-a-field-to-a-block-count/td-p/6409772 Quote
Tharwat Posted September 14, 2017 Posted September 14, 2017 I've seen people writing lisps and then using a custom field to apply the info from the lisp, but I cant figure out the connection between the 2. https://forums.autodesk.com/t5/autocad-for-mac-forum/linking-a-field-to-a-block-count/td-p/6409772 That's a work around with Diesel expression and it is not a direct FIELD object. Quote
JoeyG_77 Posted September 14, 2017 Author Posted September 14, 2017 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) ) Quote
BIGAL Posted September 15, 2017 Posted September 15, 2017 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))) Quote
JoeyG_77 Posted September 15, 2017 Author Posted September 15, 2017 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) Quote
JoeyG_77 Posted September 18, 2017 Author Posted September 18, 2017 Anyone have some input which way to go w/ this ? ... any help would be very much appreciated Quote
Recommended Posts
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.