Visual LISP, AutoLISP and General Customization

Visual LISP, AutoLISP and General Customization

Reply
Distinguished Contributor
CAD77
Posts: 125
Registered: ‎03-10-2006
Message 1 of 10 (3,650 Views)

Sum of Hatch Areas - Lisp Routine Modification.

3650 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)
)
Distinguished Contributor
Tom Smith
Posts: 3,729
Registered: ‎12-17-2003
Message 2 of 10 (3,650 Views)

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))
Distinguished Contributor
CAD77
Posts: 125
Registered: ‎03-10-2006
Message 3 of 10 (3,650 Views)

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!
Distinguished Contributor
Tom Smith
Posts: 3,729
Registered: ‎12-17-2003
Message 4 of 10 (3,650 Views)

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.
Active Member
jbechard
Posts: 9
Registered: ‎05-12-2011
Message 5 of 10 (3,456 Views)

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

*Expert Elite*
Kent1Cooper
Posts: 5,370
Registered: ‎09-13-2004
Message 6 of 10 (3,451 Views)

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
Active Member
jbechard
Posts: 9
Registered: ‎05-12-2011
Message 7 of 10 (3,441 Views)

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

Mentor
stevor
Posts: 846
Registered: ‎12-26-2005
Message 8 of 10 (3,436 Views)

Re: Sum of Hatch Areas - Lisp Routine Modification.

05-12-2011 08:16 AM in reply to: jbechard
Active Member
jbechard
Posts: 9
Registered: ‎05-12-2011
Message 9 of 10 (3,434 Views)

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.

New Member
ramtin6276
Posts: 1
Registered: ‎03-10-2012
Message 10 of 10 (2,956 Views)

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

 

Announcements
Are you familiar with the Autodesk Expert Elites? The Expert Elite program is made up of customers that help other customers by sharing knowledge and exemplifying an engaging style of collaboration. To learn more, please visit our Expert Elite website.
Need installation help?

Start with some of our most frequented solutions or visit the Installation and Licensing Forum to get help installing your software.