Jump to content

Hatch areas by layers or patterns for entire drawing or selected area


Baber62

Recommended Posts

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.

Link to comment
Share on other sites

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 by ronjonp
Link to comment
Share on other sites

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.

Link to comment
Share on other sites

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!"))
   )

Link to comment
Share on other sites

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?

Link to comment
Share on other sites

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 by ronjonp
Link to comment
Share on other sites

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