Lee Mac Posted February 1, 2010 Share Posted February 1, 2010 Not sure if this would work? ;; Summing Attributes Before Extraction (defun c:AttSum (/ *error* Get_Unique ATTLST CAT CATS CAT_TAG ENT FILE I N NEWATTLST NEWORDER NUM NUM_TAG OBJ OFILE ORD OTHER SS SYM SYM_TAG) (vl-load-com) ;; Lee Mac ~ 01.02.10 ;; ----------<< Attribute Tag Names >>---------- (setq Cat_Tag "CATEGORY" Sym_Tag "SYMBOL" Num_Tag "QUANTITY") ;; ----------<< Attribute Tag Order >>---------- (setq Ord '("Deciduous Shade Trees" "Ornamental Trees" "Evergreen Trees" "Deciduous Shrubs" "Evergreen Shrubs" "Perennials and Ornamental Grasses" "Groundcovers" "Vines" "Annuals and Bulbs" "Seed Mixes" )) ;; --------------------------------------------- (defun *error* (msg) (and ofile (close ofile)) (or (wcmatch (strcase msg) "*BREAK,*CANCEL*,*EXIT*") (princ (strcat "\n** Error: " msg " **"))) (princ)) (defun Get_Unique (lst / Remove_n x ass result) (defun Remove_n (n lst) (setq i -1) (vl-remove-if (function (lambda (x) (= (setq i (1+ i)) n))) lst)) (while (setq x (car lst)) (setq lst (cdr lst)) (while (setq ass (assoc (car x) lst)) (setq x (cons (car x) (append (cdr x) (cdr ass)))) (setq lst (Remove_n (vl-position ass lst) lst))) (setq result (cons x result))) result) (defun lst2str (lst del) (if (cdr lst) (strcat (car lst) del (lst2str (cdr lst) del)) (car lst))) (mapcar (function set) '(Cat_Tag Sym_Tag Num_Tag) (mapcar (function strcase) (list Cat_Tag Sym_Tag Num_Tag))) (setq Ord (mapcar (function strcase) Ord)) (if (and (setq i -1 ss (ssget '((0 . "INSERT") (2 . "KEY-PLANT") (66 . 1)))) (setq file (getfiled "Output File" "" "csv" 9)) (setq ofile (open file "a"))) (progn (write-line (strcat (getvar "DWGPREFIX") (getvar "DWGNAME")) ofile) (write-line "PLANT-TYPE,QUANTITY" ofile) (while (setq ent (ssname ss (setq i (1+ i)))) (setq obj (vlax-ename->vla-object ent)) (foreach att (vlax-invoke obj 'GetAttributes) (cond ( (eq Cat_Tag (strcase (vla-get-TagString att))) (setq Cat (vla-get-TextString att))) ( (eq Sym_Tag (strcase (vla-get-TagString att))) (setq Sym (vla-get-TextString att))) ( (eq Num_Tag (strcase (vla-get-TagString att))) (setq Num (distof (vla-get-TextString att)))) (t (setq Other (cons (vla-get-TextString att) Other))))) (if (and Cat Sym Num) (setq AttLst (cons (cons Cat (list (cons Sym (list (cons Num Other))))) AttLst))) (setq Other nil Cat nil Sym nil Num nil)) (setq AttLst (mapcar (function (lambda (x) (cons (car x) (vl-sort (Get_Unique (cdr x)) (function (lambda (a b) (< (car a) (car b)))))))) (Get_Unique AttLst))) (setq Cats (mapcar (function (lambda (x) (strcase (car x)))) AttLst)) (setq Ord (vl-remove-if-not (function (lambda (x) (vl-position x Cats))) Ord)) (setq newOrder (vl-remove 'nil (mapcar (function (lambda (x) (vl-position x Cats))) Ord))) (setq NewAttLst (mapcar (function (lambda (x) (nth x AttLst))) newOrder)) (setq AttLst (append NewAttLst (vl-remove-if (function (lambda (x) (vl-position x NewAttLst))) AttLst))) (foreach x Attlst (write-line (car x) ofile) (foreach y (cdr x) (write-line (strcat (car y) (chr 44) (lst2str (cdr y) (chr 44))) ofile)) (write-line "" ofile)) (setq ofile (close ofile))) (princ "\n<!> No Blocks Found <!>")) (princ)) Quote Link to comment Share on other sites More sharing options...
mexmr10 Posted February 1, 2010 Author Share Posted February 1, 2010 this is what i get: Error: bad argument type: stringp (1.0) Quote Link to comment Share on other sites More sharing options...
Lee Mac Posted February 1, 2010 Share Posted February 1, 2010 this is what i get: Error: bad argument type: stringp (1.0) EDIT: With these extra attributes, say you have two blocks with the same 'Symbol' attribute. Currently, these will be grouped and the quantities summed. What will happen at this point to the extra attributes? Quote Link to comment Share on other sites More sharing options...
One_Punchman Posted December 3, 2017 Share Posted December 3, 2017 Reviving this thread. So how do I make the program work? Copy and paste to a notepad then rename the file extension? How to execute to command after appload? Quote Link to comment Share on other sites More sharing options...
BIGAL Posted December 4, 2017 Share Posted December 4, 2017 Copy and paste to notepad saveas say Attsum.lsp no need for rename. Appload Attsum Just type Attsum on command line The C:attsum means the function following the C: can be typed on the command line to run. Quote Link to comment Share on other sites More sharing options...
One_Punchman Posted December 5, 2017 Share Posted December 5, 2017 Copy and paste to notepad saveas say Attsum.lsp no need for rename. Appload Attsum Just type Attsum on command line The C:attsum means the function following the C: can be typed on the command line to run. Thanks Mr. Bigal. Will try that. Quote Link to comment Share on other sites More sharing options...
One_Punchman Posted December 5, 2017 Share Posted December 5, 2017 So here is what happened. I opened a CAD file, created 3 attributes namely: plant-type, quantity and category. Next I created a block out of those attributes collectively, named 'key-plant'. To experiment, I inserted 2 of those blocks with their own details, as shown below: Then as instructed by Bigal, I loaded the attsum, windowed the aforementioned 2 blocks (2 blocks selected; acknowledged by AutoCAD), then an excel file was created. I opened that excel file and found this: As you can see, there is a filename location above, then 2 parameters namely the PLANT-TYPE and CATEGORY only. There were no further details that followed. Could have I made a mistake in the procedure? Quote Link to comment Share on other sites More sharing options...
Roy_043 Posted December 6, 2017 Share Posted December 6, 2017 Have you updated the 'Attribute Tag Names' section to match your tags (note: use CAPS)? Quote Link to comment Share on other sites More sharing options...
One_Punchman Posted December 6, 2017 Share Posted December 6, 2017 Thanks for the suggestion, Roy_043. I tried using capital letters in the tags before creating the 'key-plant' block, as shown below: But I still got the same excel result. Quote Link to comment Share on other sites More sharing options...
Roy_043 Posted December 6, 2017 Share Posted December 6, 2017 I repeat: Have you updated the 'Attribute Tag Names' section to match your tags (note: use CAPS)? IOW: you have to change that portion of the code. And if that does not help: post your dwg. Quote Link to comment Share on other sites More sharing options...
One_Punchman Posted December 6, 2017 Share Posted December 6, 2017 @Roy_043, sorry I'm a total newbie at this, so I don't know how to execute that last instruction. What I can do is show you the steps I did. First off I created 3 attributes that indicate 'PLANTTYPE', 'QUANTITY' AND 'CATEGORY': Second, I created the 'key-plant' block: 3rd, I inserted a 'key-plant' block called 'GJA': and another one called 'ITE' Next, I executed the ATTSUM command with the 2 blocks selected: Then an excel file was created: I got the same excel file as before. Just the 'PLANT-TYPE' and 'QUANTITY'. No indication of the GJA and/or ITE and their details. I was hoping to have something like this: There could be a lot of mistakes that I did and in fact, I don't know how to do the instruction you provided. Please bear with this newbie soul. Quote Link to comment Share on other sites More sharing options...
Roy_043 Posted December 10, 2017 Share Posted December 10, 2017 The code looks at three tags: "CATEGORY", "SYMBOL" and "QUANTITY". Only blocks that have attributes with all these tags will be processed. So you must change "SYMBOL" to "PLANTTYPE" in the Lisp code. Quote Link to comment Share on other sites More sharing options...
One_Punchman Posted January 12, 2018 Share Posted January 12, 2018 Happy New Year! Quote Link to comment Share on other sites More sharing options...
One_Punchman Posted January 12, 2018 Share Posted January 12, 2018 Still no cigar. I renamed the attsum to a text file, changed the 'SYMBOL' to 'PLANTYPE' then convert back to lsp file: Made the blocks as per previous steps: Loaded the attsum, then generated the excel file: As you can see, this is still far from the desired output. The planttype codes (GJA and ITE) and quantities (150 and 500) still do not appear in the excel file. Quote Link to comment Share on other sites More sharing options...
ReMark Posted January 12, 2018 Share Posted January 12, 2018 FYI - lisp routines that are not compiled do not have to be renamed as a text file in order to edit them. They are typically ASCII text files to begin with which means they can be opened with any ASCII text editor such as Notepad. Quote Link to comment Share on other sites More sharing options...
Roy_043 Posted January 14, 2018 Share Posted January 14, 2018 @One_Punchman: Post your dwg. Quote Link to comment Share on other sites More sharing options...
One_Punchman Posted January 15, 2018 Share Posted January 15, 2018 Sent test drawing to be sent.dwg Attsum.lsp test drawing to be sent.dwg Quote Link to comment Share on other sites More sharing options...
Roy_043 Posted January 15, 2018 Share Posted January 15, 2018 The code from post #21 is faulty. Use the code from post #14, change the 'Attribute Tag Names' as before and things should work fine. Quote Link to comment Share on other sites More sharing options...
One_Punchman Posted February 9, 2018 Share Posted February 9, 2018 Worked! Also found out that the resulting excel file could not be overwritten correctly. A new list shows up on top of the previous one (in the same excel file), so it is best to do the attsum command when the drawing is absolutely finished. Or simply erase the old excel file to get a fresh new updated one. Thanks Roy_043 and LeeMax! See you in the other threads! Quote Link to comment Share on other sites More sharing options...
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.