jones Posted May 4, 2006 Posted May 4, 2006 hi there - hoping someone can help me out. i work for a landscape architecture firm and we frequently need to calculate plant quantities from our CAD drawings, using blocks with assigned species name/quantities. the "eattext" command almost does what i'm looking for, except it doesn't add up the quantities, we have to do it manually or in excel (a pain either way). for example, using eattext we get: Ar 13 Ar 12 Ar 10 Bl 5 Bl 10 Bl 23 Cd 6 Cd 2 Cd 4 when what we really want is: Ar 35 Bl 38 Cd 12 and so on. the last firm i worked for had a handy little lisp routine called "plist" that spat out a wordpad list, so i know this can be done. any help would be greatly appreciated. Quote
rkmcswain Posted May 4, 2006 Posted May 4, 2006 What version of AutoCAD? 2005 and later can add of the quantities (and provide a real-time link, so that when you add or delete blocks, the table is updated.) Quote
jones Posted May 4, 2006 Author Posted May 4, 2006 we just switched to 2006. can you explain how to do it? thank you! Quote
rkmcswain Posted May 5, 2006 Posted May 5, 2006 See: http://aec.cadalyst.com/aec/article/articleDetail.jsp?id=180591 The part you will have to manually do is create an additional row at the bottom containing formulas to total the columns Add a row Click in the cell to edit Add a FIELD Choose Formula from the list of Fields Choose the SUM formula I just remembered, if you manually add a new row, then update the table, the added row is lost. You might wait to add your SUM row until you are ready to plot and no more changes will occur. Quote
CAB Posted May 5, 2006 Posted May 5, 2006 This may give you some options. Make sure you change the name of the block within the code. PS If you have several blocks to collect from, use this for more than one name: (setq blkname "name1,name2,name3") ;;=======================[ AttrAdd.lsp ]======================= ;;; Author: Charles Alan Butler ;;; Version: 1.0 May 5, 2006 ;;; Purpose: To add attributes in a block, from matching tags ;;; in entire drawing ;;; Requirements: -None ;;; Returns: -None ;;;============================================================== ;; (defun c:attradd (/ ss obj att attr_list result blk blkname ename i tag tmp) (setq blkname "test w attr") ; <---<< Your block name goes here (vl-load-com) (defun get_attr_lst (blk / lst) (foreach att (vlax-invoke blk 'getattributes) (setq lst (cons (cons (vla-get-tagstring att) (vla-get-textstring att)) lst)) ) ) ;; add the attribute values (defun attrnum (att num) (if (numberp (setq tmp (atoi (cdr att)))) (itoa (+ tmp (atoi num))) num ) ) (prompt "\nCounting Attributes, Please wait.") (if (setq ss (ssget "_X" (list '(0 . "INSERT") '(66 . 1) (cons 2 blkname)))) (progn (setq i -1) (while (setq ename (ssname ss (setq i (1+ i)))) (setq blk (vlax-ename->vla-object ename)) (setq attr_list (get_attr_lst blk)) (foreach att attr_list (if (assoc (setq tag (car att)) result) (setq result (subst (cons tag (attrnum att (cdr (assoc tag result)))) (assoc tag result) result)) ;; else add it (setq result (cons att result)) ) ) ) ) (prompt "\n*** No attributes found ***") ) (if result (foreach itm result (print itm) ) ) (princ) ) (prompt "\nAttribute Add Loaded, Enter AttrAdd to run.") (princ) Quote
fixo Posted May 5, 2006 Posted May 5, 2006 Try this one also: (defun C:cb (/ acsp adoc aexc awb axss blk_data blk_names cll cnt colm csht data header_list nwb row sht ss subtot tmp tot) (vl-load-com) (setq adoc (vla-get-activedocument (vlax-get-acad-object) ) acsp (vla-get-modelspace adoc) ) (vla-zoomextents (vlax-get-acad-object)) ;; to count all block references: (setq ss (ssget "_X" '((0 . "INSERT")))) ;; or, for desired blocks only: ;;; (setq bname (getstring "\n *** Enter block name(case-sensitive):\n")) ;;; (setq ss (ssget "_X" (list (cons 0 "INSERT") (cons 2 bname)))) (setq axss (vla-get-activeselectionset adoc)) (setq tot (vla-get-count axss)) (setq blk_names nil);for debug only (vlax-for blk axss (if (not (member (vla-get-name blk) blk_names)) (setq blk_names (cons (vla-get-name blk) blk_names)))) (foreach bname blk_names (setq cnt 0) (vlax-for blk axss (if (eq bname (vla-get-name blk)) (setq cnt (1+ cnt)))) (setq tmp (cons bname cnt)) (setq blk_data (cons tmp blk_data))) ;;; *** Excel part *** ;; (setq aexc (vlax-get-or-create-object "Excel.Application") awb (vlax-get-property aexc "Workbooks") nwb (vlax-invoke-method awb "Add") sht (vlax-get-property nwb "Sheets") csht (vlax-get-property sht "Item" 1) cll (vlax-get-property csht "Cells") ) (vlax-put-property csht 'Name "Block Count") (vla-put-visible aexc :vlax-true) (setq row 1 colm 1 ) (setq header_list '("NAME" "QUANTITY")) (repeat (length header_list) (vlax-put-property cll "Item" row colm (vl-princ-to-string (car header_list)) ) (setq colm (1+ colm) header_list (cdr header_list) ) ) (setq row 2 colm 1 ) (repeat (length blk_data) (setq data (car blk_data) subtot (cdr data)) (vlax-put-property cll "Item" row colm (vl-princ-to-string (car data)) ) (setq colm (1+ colm)) (vlax-put-property cll "Item" row colm (vl-princ-to-string subtot) ) (setq row (1+ row) colm 1 ) (setq blk_data (cdr blk_data)) ) (vlax-put-property cll "Item" row colm (vl-princ-to-string "Total:") ) (setq colm (1+ colm)) (vlax-put-property cll "Item" row colm (vl-princ-to-string tot) ) (vlax-invoke-method nwb 'SaveAs (strcat (getvar "dwgprefix") "BlkCount.xls") -4143 nil nil :vlax-false :vlax-false 1 2 ) (vlax-release-object cll) (vlax-release-object csht) (vlax-release-object sht) (vlax-release-object nwb) (vlax-release-object awb) (vlax-release-object aexc) (setq aexc nil) (vla-clear axss) (vla-delete axss) (vlax-release-object axss) (gc) (gc) (princ) ) ~'J'~ Quote
aoinwpb5222 Posted July 3, 2013 Posted July 3, 2013 I know this is old, but I just came upon the thread and could definitely use this as well. I tried to use both above options as .lsp separately but neither one will run. I used appload to load them, and they just run saying "Initializing"....... Any help would be appreciated. Quote
alanjt Posted July 3, 2013 Posted July 3, 2013 I know this is old, but I just came upon the thread and could definitely use this as well. I tried to use both above options as .lsp separately but neither one will run. I used appload to load them, and they just run saying "Initializing"....... Any help would be appreciated. A few years back, some of the old posted code became corrupt. Paste the code into notepad and use find & replace for the following items: ( => ( ) => ) Quote
aoinwpb5222 Posted July 3, 2013 Posted July 3, 2013 Thanks. Also found that : => : Unfortunately, neither one of these really does what the original poster (and I) are looking for. The first one just seems to add all the attribute values for the named block, and not separate values for similar attributes. For instance, in the OP it would add the numerical values for Ar 35, Bl 38 and Cd 12 and give you 85. Looking for it to add the Ar's, the Bl's and Cd's separately. The second one seems to add all the instances for blocks and give you an excel file with a "head count" for each block. Basically, BCOUNT. Each helpful in their own right, but not really what I need. Anyone have something that really does what the poster is looking for? Basically EATTEXT, but add up the values with similar attributes? 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.