Visual LISP, AutoLISP and General Customization
cancel
Showing results for 
Show  only  | Search instead for 
Did you mean: 

Sum of Hatch Lisp routine??

17 REPLIES 17
Reply
Message 1 of 18
jbechard
1732 Views, 17 Replies

Sum of Hatch Lisp routine??

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

17 REPLIES 17
Message 2 of 18
_Tharwat
in reply to: jbechard

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

 

 

Message 3 of 18
jbechard
in reply to: _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

Message 4 of 18
pbejse
in reply to: jbechard

was this the same question on the other thread? wherein you're having trouble with the code  because of version issues?

 

This thread

 

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

 

Message 5 of 18
Kent1Cooper
in reply to: jbechard


@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]?

Kent Cooper, AIA
Message 6 of 18
_Tharwat
in reply to: Kent1Cooper

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

Message 7 of 18
jbechard
in reply to: pbejse

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.

Message 8 of 18
pbejse
in reply to: Kent1Cooper

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/

 

 

 

Message 9 of 18
jbechard
in reply to: Kent1Cooper

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.

Message 10 of 18
pbejse
in reply to: jbechard

(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))

 

Message 11 of 18
_Tharwat
in reply to: pbejse

(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)
)

Message 12 of 18
pbejse
in reply to: _Tharwat

 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

.

 

 

 

 

 

 

Message 13 of 18
jbechard
in reply to: pbejse

Seems to be getting closer.  At least this time I get a new error "Expects a point or Last/CLass
; error: Function cancelled"

Message 14 of 18
pbejse
in reply to: jbechard


@jbechard wrote:

 I have tried the 'hatcharea" code, which wants to work,

Smiley Very Happy

 

I modified the hatchareas code form the original thread , you can try that one (post #10)

 

Message 15 of 18
jbechard
in reply to: _Tharwat

same error as previous "*Invalid selection*
Expects a point or Last/CLass
; error: Function cancelled

Message 16 of 18
stevor
in reply to: jbechard

If not already stated, the Autocad area command does not work for Hatch entities before about 2006, as noted in jtbworld's hatchb.lsp.
S
Message 17 of 18
Kent1Cooper
in reply to: jbechard


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

Kent Cooper, AIA
Message 18 of 18
pbejse
in reply to: stevor


@stevor wrote:
If not already stated, the Autocad area command does not work for Hatch entities before about 2006, as noted in jtbworld's hatchb.lsp.

Ahhh.. that is correct, should have read the other thread before jumping in.with that suggestion

 

Thanks stevor

Can't find what you're looking for? Ask the community or share your knowledge.

Post to forums  

Autodesk Design & Make Report

”Boost