• Industries
  • Products
  • Buy
  • Services & Support
  • Communities
  • Discussion Groups

    Visual LISP, AutoLISP and General Customization

    Reply
    Distinguished Contributor
    Posts: 125
    Registered: ‎03-10-2006

    Sum of Hatch Areas - Lisp Routine Modification.

    1975 Views, 9 Replies
    09-18-2007 10:18 AM
    Hello,

    Can someone help me modify this lisp routine to sum the hatch areas it calculates?

    I would like to be able to select the hatches one at a time or with a window and have the sum of the areas displayed.

    Thanks to Daniel J. Altamura for the following routine: (discovered at http://discussion.autodesk.com/thread.jspa?messageID=5536798 )



    (defun c:HatchArea (/ ENT)
    (if (>= (atof (substr (getvar "acadver") 1 4)) 16.2)
    (progn
    (while (not (setq ENT (entsel "\nSelect hatch: ")))
    (prompt "\nNo object selected.")
    )
    (setq ENT (entget (car ENT)))
    (if (= (cdr (assoc 0 ENT)) "HATCH")
    (progn
    (setq ENT (vlax-ename->vla-object (cdr (assoc -1 ENT))))
    (alert
    (strcat
    "\nArea = "
    (if (or (= (getvar "lunits") 3) (= (getvar "lunits") 4))
    (strcat
    (rtos (vla-get-area ENT) 2)
    " sq. in. ("
    (rtos (/ (vla-get-area ENT) 144) 2)
    " sq. ft.)"
    )
    (rtos (vla-get-area ENT))
    )
    )
    )
    )
    (prompt "\nThis is not a hatch object.")
    )
    )
    )
    (princ)
    )
    Please use plain text.
    Distinguished Contributor
    Posts: 3,729
    Registered: ‎12-17-2003

    Re: Sum of Hatch Areas - Lisp Routine Modification.

    09-18-2007 11:34 AM in reply to: CAD77
    (defun c:HatchAreas (/ sset i area obj)
    (if (>= (atof (substr (getvar "acadver") 1 4)) 16.2)
    (progn
    (prompt "\nSelect hatches: ")
    (if (setq sset (ssget '((0 . "hatch"))))
    (progn
    (setq
    i (1- (sslength sset))
    area 0)
    (while (>= i 0)
    (setq
    obj (vlax-ename->vla-object (ssname sset i))
    area (+ area (vla-get-area obj)))
    (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))
    Please use plain text.
    Distinguished Contributor
    Posts: 125
    Registered: ‎03-10-2006

    Re: Sum of Hatch Areas - Lisp Routine Modification.

    09-18-2007 12:10 PM in reply to: CAD77
    Thank you very much, Tom. I appreciate your time.

    Works great!
    Please use plain text.
    Distinguished Contributor
    Posts: 3,729
    Registered: ‎12-17-2003

    Re: Sum of Hatch Areas - Lisp Routine Modification.

    09-18-2007 01:07 PM in reply to: CAD77
    You'e welcome. It was really an easy adaptation of Daniel's routine. You can see the differences in working with selection sets versus single objects. You can use an ssget filter list to avoid having to check the entity type, but then you have to use some kind of loop to cycle through the selection set.
    Please use plain text.
    Active Member
    jbechard
    Posts: 9
    Registered: ‎05-12-2011

    Re: Sum of Hatch Areas - Lisp Routine Modification.

    05-12-2011 06:45 AM in reply to: CAD77

    Can someone please tell me what I am doing wrong with trying to add this sum of hatch areas lisp routine.  I have copied the routine directly from here and brought it into notepad.  I saved it as a .lsp.  I used the appload function to load the new lisp routine and it says it was successful.  But when I type the command hatchareas, there is nothing.  No error, no unknown command.  It just goes back to command without doing anything or asking for any options.  I am using Acad 2004.

     

    Thanks,

    Jeff

    Please use plain text.
    *Expert Elite*
    Kent1Cooper
    Posts: 4,057
    Registered: ‎09-13-2004

    Re: Sum of Hatch Areas - Lisp Routine Modification.

    05-12-2011 07:14 AM in reply to: jbechard

    jbechard wrote:

    ....when I type the command hatchareas, there is nothing.  No error, no unknown command.  It just goes back to command without doing anything or asking for any options.  I am using Acad 2004.

    ....


    I'm in ADT2004, and it does the same for me.  It's the (if) test at the top.  My ACADVER is 16.0, and that's earlier than what it's testing for.  If I take out the test, I get an "unknown name: Area" message.  The Area property of Hatch patterns was apparently added to a later version, but isn't available for me -- hence the (if) test.  In earlier versions that don't recognize that property of Hatch patterns, it would need to be done differently, if it's even possible.  You might try Searching the discussion group for some other way of calculating such areas, if there is one.

    Kent Cooper
    Please use plain text.
    Active Member
    jbechard
    Posts: 9
    Registered: ‎05-12-2011

    Re: Sum of Hatch Areas - Lisp Routine Modification.

    05-12-2011 07:48 AM in reply to: CAD77

    Thank you for your quick response.

     

    That's unfortunate that it doesn't work with the earlier versions.  Hopefully there's another way that it can be done out there. 

     

    Thank you for the explanation.  It makes sense why it does what it does once I tried it.

     

    Jeff

    Please use plain text.
    Mentor
    Posts: 766
    Registered: ‎12-26-2005

    Re: Sum of Hatch Areas - Lisp Routine Modification.

    05-12-2011 08:16 AM in reply to: jbechard
    Please use plain text.
    Active Member
    jbechard
    Posts: 9
    Registered: ‎05-12-2011

    Re: Sum of Hatch Areas - Lisp Routine Modification.

    05-12-2011 08:22 AM in reply to: stevor

    I just tried that routine and all it seems to do is recreate my boundaries.  The problem is that when I have 2 items, for example, one circle inside of another, I need to know the area of what the hatching would be in between them.  Like a thick line.  But with using the boundaries to get my sum of the areas, it doesn't factor in that I am hatching in between two objects, as opposed to fully hatching both objects.  So I have a zone lisp routine that gives me the sum of all boundaries, but again, it doesn't factor in the actual area that is hatched.  That's why I need something that actually recognizes the hatch itself.

    Please use plain text.
    New Member
    Posts: 1
    Registered: ‎03-10-2012

    Re: Sum of Hatch Areas - Lisp Routine Modification.

    03-10-2012 12:42 PM in reply to: jbechard

    Can someone help me :

    I draw Several hatches in separate layers and  I need a lisp that calculate cumulative area of they hatches in separate layers and print the results to an excel table. similar this :

     

    cumulative area

    Name of Layer

     ..........................................................................................

    Layer1

      ..........................................................................................

    Layer2

     

    .

    .

    .

      ..........................................................................................

    Layer n

     

    Please use plain text.