Baber62 Posted October 31, 2017 Share Posted October 31, 2017 I am looking for a lisp routine that will export hatch areas by layers and/or pattern for an entire drawing or a selected area in a drawing to an excel file. I have a large number of drawings that I have to get through (over 100) and having to prepare a bill of quantities. Any assistance would be gratefully appreciated. Quote Link to comment Share on other sites More sharing options...
ronjonp Posted October 31, 2017 Share Posted October 31, 2017 (edited) Here's a quick one: (defun c:hareas (/ _writefile a b key out s) (defun _writefile (filename lst / file) (cond ((and (eq 'str (type filename)) (setq file (open filename "w"))) (foreach x lst (write-line x file)) (close file) filename ) ) ) (initget 0 "Pattern Layer") (if (and (or (setq key (getkword "\nPattern or LayerName [<Pattern>]: ")) (setq key "Pattern")) (setq s (ssget '((0 . "hatch")))) ) (progn (setq s (mapcar '(lambda (x) (cons (if (= "Pattern" key) (vla-get-patternname x) (vla-get-layer x) ) (if (vl-catch-all-error-p (setq a (vl-catch-all-apply 'vla-get-area (list x)))) 0.0 a ) ) ) (mapcar 'vlax-ename->vla-object (vl-remove-if 'listp (mapcar 'cadr (ssnamex s)))) ) ) (foreach h s (if (setq b (assoc (car h) out)) (setq out (subst (cons (car b) (+ (cdr b) (cdr h))) b out)) (setq out (cons h out)) ) ) (print (_writefile (strcat (getvar 'dwgprefix) (vl-filename-base (getvar 'dwgname)) "_Hatch_" key "_Areas.csv" ) (mapcar '(lambda (x) (strcat (car x) "," (vl-princ-to-string (cdr x)))) out) ) ) (if (setq b (vl-remove-if-not '(lambda (x) (= 0 (cdr x))) out)) (alert (strcat (itoa (length b)) " hatches have no area property!")) ) ) ) (princ) ) (vl-load-com) Edited October 31, 2017 by ronjonp Quote Link to comment Share on other sites More sharing options...
Baber62 Posted October 31, 2017 Author Share Posted October 31, 2017 Thanks ronjonp, works fine for the pattern, however, I can't seem to select the layer name, tried entering the layer name itself but it's not working. Also routine does it for the whole drawing also need it to cover a selection set. Quote Link to comment Share on other sites More sharing options...
ronjonp Posted October 31, 2017 Share Posted October 31, 2017 Thanks ronjonp, works fine for the pattern, however, I can't seem to select the layer name, tried entering the layer name itself but it's not working. Also routine does it for the whole drawing also need it to cover a selection set. Change: (setq s (ssget "_X" '((0 . "hatch")))) to: (setq s (ssget '((0 . "hatch")))) The way the code is written is to either tally hatch by layer name, or by hatch pattern name. No filter is built in. I also added an alert above for hatches without an area property: (if (setq b (vl-remove-if-not '(lambda (x) (= 0 (cdr x))) out)) (alert (strcat (itoa (length b)) " hatches have no area property!")) ) Quote Link to comment Share on other sites More sharing options...
Baber62 Posted November 2, 2017 Author Share Posted November 2, 2017 Hi ronjonp sorry couldn't get back to you earlier, still having trouble with the code to get the output by layer, any ideas where I'm going wrong? Quote Link to comment Share on other sites More sharing options...
Baber62 Posted November 2, 2017 Author Share Posted November 2, 2017 Here's the outputs Iam looking for hatchareas-pattern.csv hatchareas-layername.csv Quote Link to comment Share on other sites More sharing options...
ronjonp Posted November 2, 2017 Share Posted November 2, 2017 (edited) The output for patterns you're looking for is not even close to your initial request? They layer output ( I'm guessing totals per layer ) should be fine other than it does not create a header. Pattern Scale Colour Area Ar-Con 10 Red 20 Ar-Con 50 Red 30 Ar-Con 50 Blue 45 Edited November 2, 2017 by ronjonp Quote Link to comment Share on other sites More sharing options...
Baber62 Posted November 6, 2017 Author Share Posted November 6, 2017 Thanks for your assist ronjonp 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.