Can anyone provide me with a lisp routine for finding the sum of all selected HATCH areas, as well as everything I need to do in order to get it working in Acad. I've seen the posting here with the sum of hatch area lisp routine, but I can't seem to get that to work. Any help is very appreciated.
Thank you,
Jeff
Is this what you mean ?
(defun c:TesT (/ ss)
(if (setq ss (ssget ":L" '((0 . "HATCH"))))
(alert (strcat "The sum of selected Hatches is : "
" "
(itoa (sslength ss))
)
)
(alert "No Hatches found ")
)
(princ)
)
Tharwat
Unfortunately this adds up the sum of total hatch objects. What I need it the sum of the area of all hatches.
But thank you very much for trying to help me out.
Jeff
was this the same question on the other thread? wherein you're having trouble with the code because of version issues?
anyhoo try this approach
(defun c:HatchArea (/ area sset) (vl-load-com) (cond ((and (ssget ":L" '((0 . "Hatch"))) (setq area 0) (vlax-for H (setq sset (vla-get-activeselectionset (vla-get-activedocument (vlax-get-acad-object)))) (setq area (+ (vla-get-area h) area)) ) (alert (strcat "\nTotal area = " (if (or (= (getvar "lunits") 3) (= (getvar "lunits") 4)) (strcat (rtos area 2) " sq. in. (" (rtos (/ area 144) 2) " sq. ft.)") (rtos area)))) (vla-delete sset) )) ) )
@jbechard wrote:Can anyone provide me with a lisp routine for finding the sum of all selected HATCH areas, as well as everything I need to do in order to get it working in Acad. I've seen the posting here with the sum of hatch area lisp routine, but I can't seem to get that to work. Any help is very appreciated.
....
Have you done what jbechard described in Message 5 there? If so, in what way does it not work? Does the command fail to load, or simply do nothing as for jbechard, or does it not recognize the command name, or does it return incorrect information, or something else? Do you have a new-enough version of AutoCAD to use that routine [see Message 6 there]?
Although the routine that was given by pBe is perfect , I hope that pbe do not mind to post these codes that I have been arranging when he did post his .
(defun c:TesT (/ area ss)
(vl-load-com)
(setq area 0)
(if (setq ss (ssget ":L" '((0 . "HATCH"))))
((lambda (i / sset obj-area)
(while
(setq sset (ssname ss (setq i (1+ i))))
(setq obj-area (vla-get-area (vlax-ename->vla-object sset)))
(setq area (+ obj-area area))
)
(alert (strcat "The sum of selected Hatches is : "
" "
(rtos area 2)
)
)
)
-1
)
(alert "No Hatches found ")
)
(princ)
)
Tharwat
This one is the right idea, but if comes up with the error "; error: ActiveX Server returned the error: unknown name: Area". I believe it comes down Acad 2004 not being new enough to be able to figure out the area of hatching.
Hopefully I'm wrong, but as of yet, nothing has worked. But this has been the closest so far 😉
Thanks again.
I see what you mean kent.
guess we need to write a code for retriving the hatch area some other way
why not try the area command and (getvar 'Area) then add from that/
Actually I am jbechard. I have tried the 'hatcharea" code, which wants to work, but gives me an error. Then I've tried the routine "hatchareas" and it seems to do nothing. No unknown command, no error, just goes back to the command line.
(defun c:HatchAreas (/ sset i area obj) (progn (prompt "\nSelect hatches: ") (if (setq sset (ssget '((0 . "hatch")))) (progn (setq i (1- (sslength sset)) area 0) (while (>= i 0) (setq obj (ssname sset i)) (command "_area" "_Object" obj) (setq area (+ (getvar 'Area) area)) (setq i (1- i))) (alert (strcat "\nTotal area = " (if (or (= (getvar "lunits") 3) (= (getvar "lunits") 4)) (strcat (rtos area 2) " sq. in. (" (rtos (/ area 144) 2) " sq. ft.)") (rtos area))))))) (princ))
(defun c:TesT (/ area ss)
(vl-load-com)
(setq area 0)
(if (setq ss (ssget ":L" '((0 . "HATCH"))))
((lambda (i / sset obj-area)
(while
(setq sset (ssname ss (setq i (1+ i))))
(setq obj-area (command "_.area" "_object" sset))
(setq area (+ (getvar 'area) area))
)
(alert (strcat "The sum of selected Hatches is : "
" "
(rtos area 2)
)
)
)
-1
)
(alert "No Hatches found ")
)
(princ)
)
I hope that pbe do not mind to post these codes that I have been arranging when he did post his .
Just post your code tharwat, the OP appreciates all the hlep he can get.
keep on coding my friend
.
Seems to be getting closer. At least this time I get a new error "Expects a point or Last/CLass
; error: Function cancelled"
@jbechard wrote:Actually I am jbechard. ....
Sorry about not noticing that this thread is under the same name -- I didn't even look at the name, assuming that someone referring to that other thread would be a different person.... But as has been made clear enough by now, it all boils down to the problem that earlier versions of AutoCAD don't recognize an Area property for Hatch patterns.
There are routines on this forum to recreate the boundaries of Hatch patterns that don't have them -- I'm not sure whether they are also version-dependent. You might be stuck with doing something like that, and getting the areas of those boundaries. But I couldn't say whether any of those will recreate both an inside and outside boundary of a pattern with a hole in it [or multiple inside boundaries if there are multiple holes], so that you could subtract the area(s) of the inner one(s) from that of the outer one.