Polylines areas

Discussion in 'AutoCAD' started by eodeod, Mar 22, 2005.

  1. eodeod

    eodeod Guest

    Hi all,

    I have a drawing with over 500 polylines in it, all closed. Is there a way to calculate the area of each polyline (by clicking on the polyline itself) and then print the area inside the polyline itsself as a text.

    I'm not good in programming or writing any lisps, looked all over the internet but all in vein.

    Anyhelp is really appreciated.

    thank you very much
     
    eodeod, Mar 22, 2005
    #1
  2. eodeod

    Adesu Guest

    Hi eodeod,try this

    (defun c:cap (/ ss cnt ssl ssn are)
    (vl-load-com)
    (setq ss (ssget "x" '((0 . "LWPOLYLINE"))))
    (setq cnt 0)
    (setq ssl (sslength ss))
    (repeat ssl
    (setq ssn (ssname ss cnt))
    (setq are (vlax-curve-getarea ssn))
    (princ "\n")(princ cnt)(princ " = ")(princ are)
    (setq cnt (1+ cnt))
    )
    )


    to calculate the area of each polyline (by clicking on the polyline itself)
    and then print the area inside the polyline itsself as a text.
     
    Adesu, Mar 22, 2005
    #2
  3. eodeod

    Adesu Guest

    or
    defun c:cap (/ ss cnt ssl ssn are)
    (vl-load-com)
    (setq ss (ssget "x" '((0 . "LWPOLYLINE"))))
    (setq cnt 0)
    (setq ssl (sslength ss))
    (setq hei (getvar "textsize"))
    (repeat ssl
    (setq ssn (ssname ss cnt))
    (setq sse (entget ssn))
    (setq i 0)
    (foreach b
    (vl-remove-if-not
    (function
    (lambda (a) (= (car a) 10))) sse)
    (set (read (strcat "pt" (itoa (setq i (1+ i))))) (cdr b)))
    (setq are (vlax-curve-getarea ssn))
    (command "_text" "_non" pt1 hei "0" are "")
    ;(princ "\n")(princ cnt)(princ " = ")(princ are)
    (setq cnt (1+ cnt))
    )
    )
     
    Adesu, Mar 22, 2005
    #3
  4. eodeod

    eodeod Guest

    Thank you for your efforts.

    I loaded the first program, it only list the areas of the polylines in the command box. Not very helpful

    When I try to load the second lisp I receive the following msg
    "; error: bad argument type: numberp: nil"

    Am I doing anything wrong here?
     
    eodeod, Mar 22, 2005
    #4
  5. eodeod

    eodeod Guest

    The attached file
     
    eodeod, Mar 22, 2005
    #5
  6. eodeod

    hmsilva Guest

    Hi eodeod

    Try this...

    (defun c:AT()
    (COMMAND "AREA" "O" PAUSE "" "TEXT" "J" "R" PAUSE "" "" (rtos (GETVAR "AREA") 2 2))
    (PRINC)
    )

    Cherrs

    Henrique
     
    hmsilva, Mar 22, 2005
    #6
  7. eodeod

    eodeod Guest

    Thank you very much Henrique

    Works like a chram. Tok me an hour and a half to finsh 50 polylines. With your lisp finshed them in 10 min.

    Really appreciate it.
     
    eodeod, Mar 22, 2005
    #7
  8. eodeod

    hmsilva Guest

    If you need to add the txt
    use this

    (defun c:addtxt ( / )
    (setq AR_TOTAL 0)
    (princ "\nSelect text to add...")
    (setq OBJS (ssget '((0 . "TEXT"))))
    (if (/= OBJS nil)
    (progn
    (princ "\n")
    (setq gr (ssadd))
    (setq QUANT (sslength OBJS))
    (setq POSICAO 0 valor 0.0)
    (repeat QUANT
    (setq TEXTO (cdr (assoc 1 (entget (ssname OBJS POSICAO)))))
    (setq VALOR (+ VALOR (atof TEXTO)))
    (setq POSICAO (+ POSICAO 1))
    )
    (princ (strcat "\nTotal : " (rtos VALOR 2)))
    (command "text" pause "" ""(strcat "Total = "(rtos VALOR 2) ""))
    )
    (princ "\nNo text select !")
    )
    (princ)
    )

    Cherrs

    Henrique
     
    hmsilva, Mar 22, 2005
    #8
  9. eodeod

    Vxc Guest

    Henrique when You post your code translate the variable to ingles so all can
    understand better :)

    Por mim é na boa mas eles são capazes de nao perceber por vezes o
    significado de cada variável. =)

    Vxc
     
    Vxc, Mar 22, 2005
    #9
  10. eodeod

    hmsilva Guest

    tens razao...

    Viste o codigo modificado para abrir um dwg e ficar logo activo???

    Henrique
     
    hmsilva, Mar 22, 2005
    #10
  11. eodeod

    Matt Trucks Guest

    Is there a way to obtain the square footage of closed polylines in this
    manner?
    That would be a very useful tool.
     
    Matt Trucks, Mar 22, 2005
    #11
  12. eodeod

    hmsilva Guest

    Try this...

    (defun c:ASF()
    (COMMAND "-UNITS" "3" "" "" "" "" "")
    (COMMAND "AREA" "O" PAUSE "" )
    (setq A_1 (GETVAR "AREA"))
    (setq A_2 (* A_1 0.0069445))
    (setq A_T (rtos A_2 2 3))
    (COMMAND "TEXT" "J" "R" PAUSE "" "" (strcat A_T" SQ.FT.") 2 3)
    (PRINC)
    )


    Cherrs

    Henrique
     
    hmsilva, Mar 22, 2005
    #12
  13. eodeod

    Matt Trucks Guest

    Thanks man you are the auto LISP master!!! One more question how would i
    make it so there is no decimal point and just rounds to the higher #?
    Something with the Units?
    167.645SQ. FT. instad of that it qould be just 168 SQ. FT.
     
    Matt Trucks, Mar 22, 2005
    #13
  14. eodeod

    hmsilva Guest

    (defun c:ASF()
    (COMMAND "-UNITS" "3" "" "" "" "" "")
    (COMMAND "AREA" "O" PAUSE "" )
    (setq A_1 (GETVAR "AREA"))
    (setq A_2 (* A_1 0.00694444))
    (setq A_T (rtos A_2 2 0))
    (COMMAND "TEXT" "J" "R" PAUSE "" "" (strcat A_T" SQ.FT.") 2 0)
    (PRINC)
    )


    Cherrs

    Henrique
     
    hmsilva, Mar 22, 2005
    #14
  15. eodeod

    Matt Trucks Guest

    Yes thats it man!!!! Thanks alot!! I really appreciate your help.
     
    Matt Trucks, Mar 22, 2005
    #15
  16. eodeod

    Ken Guest

    Can this value be a mtext?
     
    Ken, Mar 23, 2005
    #16
  17. eodeod

    hmsilva Guest

    Yes...

    Change

    (COMMAND "TEXT" "J" "R" PAUSE "" "" (strcat A_T" SQ.FT.") 2 0)

    to


    (command "mtext" pause pause (strcat A_T" SQ.FT.") "")

    Henrique
     
    hmsilva, Mar 23, 2005
    #17
Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments (here). After that, you can post your question and our members will help you out.