Results 1 to 8 of 8

Thread: LISP Routine that works with AREA command

  1. #1
    Member
    Join Date
    2004-07
    Posts
    5
    Login to Give a bone
    0

    Default LISP Routine that works with AREA command

    Does anyone know of a LISP routine that will take the AREA of a a CLOSED POLYLINE and create text on the drawing in an ATTRIBUTE block? Cost accounting would like me to tell them the SQUARE FOOTAGE of different rooms in our company's buildings so they can allocate costs by department based on the area that they occupy. I assume that many other companies do this too. Does anyone know of someone who has already created this?

  2. #2
    All AUGI, all the time
    Join Date
    2015-12
    Location
    Central Oregon
    Posts
    591
    Login to Give a bone
    0

    Default Re: LISP Routine that works with AREA command

    Here's a routine I use that adds the square footage as Text. It wouldn't be too difficult to modify it to use an attributed block though.

    Code:
    ;; =================================================
    ;; 2002 By Luis Esquivel
    ;; put the area in sq-ft of selected closed areas...
    ;; modified 11/22/03 by Jeff Mishler to allow use within
    ;; PS Viewport and to accept a Polyline that was created
    ;; by selecting the startpoint as the endpoint, technically
    ;; it is closed but the closed property isn't set.
    ;;
    ;; Command: PUTAREA
    
    ;;;(addtext <string> <point> <real>)
    (defun addtext (textstring insertionpoint height / aa)
      (vl-load-com)
      (setq aa (vla-get-activedocument (vlax-get-acad-object)))
      (vla-addtext
    	      (if (= 1 (vla-get-activespace aa))
    		(vla-get-modelspace aa)
    		(if (= (vla-get-mspace aa) :vlax-true)
    		  (vla-get-modelspace aa)
    		  (vla-get-paperspace aa)
    		  )
    		)
    	      textstring
    	      (vlax-3d-point insertionpoint)
    	      height)
      )
    
    (defun add-comma  (txt / strl cont1 lth cont txt1)
      (setq strl  (strlen txt)
     cont1 1
     txt1  "")
      (while (and (/= (substr txt cont1 1) ".") (<= cont1 strl))
        (setq cont1 (1+ cont1)))
      (setq lth   (1- cont1)
     cont1 1
     cont  (1- lth))
      (if (> lth 3)
        (progn
          (while (< cont1 lth)
     (setq let  (substr txt cont1 1)
           txt1 (strcat txt1 let))
     (if (and (zerop (rem cont 3)) (eq (type (read let)) 'INT))
       (setq txt1 (strcat txt1 ",")))
     (setq cont  (1- cont)
           cont1 (1+ cont1)))
          (while (<= cont1 strl)
     (setq txt1  (strcat txt1 (substr txt cont1 1))
           cont1 (1+ cont1)))
          txt1)
        txt))
    
    (defun get-last-coord (obj / COORDS LAST_COORD)
      (setq coords (vla-get-coordinates obj)
    	coords (vlax-safearray->list (vlax-variant-value coords))
    	coords (reverse coords)
    	last_coord (list (cadr coords)(car coords)
    			 )
    	)
      last_coord
      )
    
    (defun C:PUTAREA  (/ ent vla_obj pt objname vla_text aa)
      (while (setq ent (entsel "\nSelect closed object: "))
        (setq vla_obj (vlax-ename->vla-object (car ent))
       objname (vla-get-objectname vla_obj))
        (if
          (vlax-property-available-p vla_obj 'area)
           (progn
      (if
        (or
          (= "AcDbCircle" objname)
          (and (wcmatch (vla-get-objectname vla_obj) "*Polyline")
    	   (or  (= :vlax-true (vla-get-closed vla_obj))
    		(equal (vlax-safearray->list
    		     (vlax-variant-value
    		       (vla-get-coordinate vla_obj '0)))
    		   (get-last-coord vla_obj)
    		   0.001)
    		)
    	   )
          )
         (progn
           (if (setq pt (getpoint "\nPick text placement: "))
      (progn
        (setq vla_text
        (addtext
          (strcat
            (add-comma
              (rtos
         (vla-get-area vla_obj)
         2
         0))
            " S.F.")
          pt
          (getvar "textsize")))
    
        ;; alignment to left
        (vla-put-alignment vla_text acAlignmentCenter)
    
        (vla-put-textalignmentpoint
          vla_text
          (vlax-3d-point pt))
    
        ;; use current textstyle
        (vla-put-stylename
          vla_text
          (vla-get-name
            (vla-get-activetextstyle
       (setq aa (vla-get-activedocument
           (vlax-get-acad-object)))))))))
         (prompt "\nNot a closed object. ")
        ))))
      (princ))
    (princ)
    HTH,
    Jeff

  3. #3
    The Silent Type Mike.Perry's Avatar
    Join Date
    2000-11
    Posts
    13,656
    Login to Give a bone
    0

    Default Re: LISP Routine that works with AREA command

    Hi

    If you're using AutoCAD 2005 you might want to take a look at using FIELDS instead, the following threads discuss that topic -

    Formatting for Precision in Fields

    Fields again

    +

    http://intervision.hjem.wanadoo.dk/ -> AutoLISP Archive (from the left hand side menu) -> Roomarea.lsp & Room_no.dwg

    http://www.llpsite.com/freeware.htm -> Drawing Aids (near the bottom) -> areacalc.zip

    Have a good one, Mike

  4. #4
    Member
    Join Date
    2004-07
    Posts
    5
    Login to Give a bone
    0

    Default Re: LISP Routine that works with AREA command

    Thanks a bunch, Mike!
    I'm still with AutoCAD 2004. I'll try out the other two routines.
    Thanks again,
    Paul

  5. #5
    Member
    Join Date
    2004-07
    Posts
    5
    Login to Give a bone
    0

    Default Re: LISP Routine that works with AREA command

    Jeff, I'm not yet savy enought to modify (or even understand) AutoLISP code. Thanks for the info. Perhaps someone else will be able to modify it.
    What does "HTH" mean?
    Paul

  6. #6
    All AUGI, all the time
    Join Date
    2015-12
    Location
    Central Oregon
    Posts
    591
    Login to Give a bone
    0

    Default Re: LISP Routine that works with AREA command

    HTH = Hope That Helps

    Paul, You don't need to modify it at all if you just want to label the square footages. Just load it and run it with the "PUTAREA" command. This code is set-up to use feet. If your base units are inches then the code will need to be adjusted for that.

    If you absolutely need the format to be in block form, if you provide me with the block name & attribute tag string (the actual block drawing would be helpful) I will modify the code as needed.

  7. #7
    Woo! Hoo! my 1st post
    Join Date
    2015-10
    Posts
    1
    Login to Give a bone
    0

    Default Re: LISP Routine that works with AREA command

    Can anyone give a lisp command to get the area in Square ft instead of Square Meter in Area command output?

  8. #8
    Member
    Join Date
    2012-01
    Posts
    32
    Login to Give a bone
    0

    Default Re: LISP Routine that works with AREA command

    Quote Originally Posted by Paul.C.Rasmussen View Post
    Does anyone know of a LISP routine that will take the AREA of a a CLOSED POLYLINE and create text on the drawing in an ATTRIBUTE block? Cost accounting would like me to tell them the SQUARE FOOTAGE of different rooms in our company's buildings so they can allocate costs by department based on the area that they occupy. I assume that many other companies do this too. Does anyone know of someone who has already created this?
    Non Free Plug-in us$20 (AreaMeasure By KIM) will cover any unit(drawing unit and output you desire and will get the job done quickly.

Similar Threads

  1. LISP routine for Area Command
    By Mac Demer in forum AutoCAD General
    Replies: 12
    Last Post: 2010-07-14, 06:24 PM
  2. Unknown Command Error, but routine works?
    By Brian Benton in forum AutoLISP
    Replies: 2
    Last Post: 2006-10-13, 04:16 PM
  3. LISP Block Insert routine no longer works once a parameter is modified
    By JAC.95598 in forum Dynamic Blocks - Technical
    Replies: 1
    Last Post: 2005-11-22, 04:50 AM
  4. Area routine that works like a hatch pick point
    By doggarn6622 in forum Land Desktop - General
    Replies: 2
    Last Post: 2004-09-13, 03:50 AM
  5. Area routine that works like hatch pickpoint
    By doggarn6622 in forum AutoCAD General
    Replies: 6
    Last Post: 2004-09-11, 08:12 PM

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •