Area Lisp Help please

Discussion in 'AutoCAD' started by Pad, Oct 1, 2004.

  1. Pad

    Pad Guest

    Hello

    ive found this lisp for claculating areas from a polyline then adding the
    area text to the drawing. ive modifed it slightly so it works in my
    template and in metres.
    but
    i need to find away to set the number of decimal places of the square metre
    area or at least change it so it displays to one decimal place hardcoded.
    At the moment it displays t o3 decimal places. Changing the unit precision
    to 1 has no affect.
    i'm not the greatest at lisp so any help would be great.

    thanks
    pad


    the lisp:

    ;;;M2 Lisp - Version 1.0 - 17th October 2001
    ;;;=============================================================
    ;;;This function will calculate an irregular area (m2)
    ;;;using boundary detection. The user then has the
    ;;;option of placing a text label into the drawing using
    ;;;the current text style/height at a user defined
    ;;;insertion point.
    ;;;=============================================================
    ;;;Written by Kenny Ramage October 2001
    ;;;=============================================================
    ;;;=============================================================
    ;;;Define Main Function
    ;;;=============================================================

    (defun C:M2A ( / os oom laag oec oudosmode p q opp opp1 oppm oppma oppmat
    tekst pos pos2 flag1 antw lw a b)



    (setvar "cmdecho" 0)

    ;; change direction to 0 and clockwise to n
    (command "units" "" "" "" "" "0" "n" )

    (command "undo" "m")

    (setq oom (getvar "orthomode")
    laag (getvar "clayer")
    oudosmode (getvar "osmode")
    olderr *error*
    *error* opperr
    );setq

    (setvar "orthomode" 0)


    (print)
    (prompt "\nIrregular Area Lisp V-1.0 Written by Kenny Ramage -
    ")



    (setq opp 0.0)

    (command "Layer" "m" "2" "")

    (while

    (setq a (getpoint "\nSelect Internal Point: "))

    (command "-Boundary" a "")

    (setq b (entlast))

    (redraw b 1)

    (command "area" "O" "L")

    (setq opp1 (getvar "area"))

    (setq opp (+ opp opp1))

    ;(redraw b 4)

    );while


    (setq oppm (/ opp 1)
    oppma (rtos oppm 2 3)
    oppmat (strcat oppma "m")
    tekst (strcat "\nArea = " oppmat "2")
    );setq

    (command "layer" "m" laag "")

    (prompt tekst)

    (setq flag1 T)

    (while flag1

    (setq antw (getstring "\nInsert Area Label? [y/n] <y> : "))

    (setq antw (strcase antw))

    (if (or (= antw "Y")(= antw ""))

    (progn
    (if (not (tblsearch "layer" "4"))
    (command "layer" "m" "4" "c" "4" "4" "")
    (command "layer" "t" "4" "on" "4" "u" "4" "s" "4" "")
    );if

    (setvar "osmode" 0)
    (setq pos (getpoint "\nInsertion Point : "))

    (if (= (cdr (assoc 40 (tblsearch "style" (getvar
    "textstyle")))) 0)
    (command "text" "j" "c" pos "" "0" oppmat)
    (command "text" "j" "c" pos "0" oppmat)
    );if

    (setq pos2 (cadr (textbox (entget (entlast))))
    pos2 (list (+ (car pos)(/ (car pos2) 2.0)) (+ (cadr
    pos)(cadr pos2)))
    );setq

    (if (= (cdr (assoc 40 (tblsearch "style" (getvar
    "textstyle")))) 0)
    (command "text" "j" "tl" pos2 "" "0" "2")
    (command "text" "j" "tl" pos2 "0" "2")
    );if

    (command "scale" "l" "" pos2 ".5")

    );progn

    );if

    (if (or (or (= antw "Y")(= antw "N")(= antw "")))

    (setq flag1 nil)
    );if

    );while


    ;;;=========================================================================
    =========
    ;;;Reset System Variables and Restore Error Handler
    ;;;=========================================================================
    =========

    (setq *error* olderror)
    (command "layer" "m" laag "")
    (setvar "osmode" oudosmode)
    (setvar "orthomode" oom)

    ;; change direction back to 270 and clockwise to y
    (command "units" "" "" "" "" "90" "y")
    (setvar "CMDECHO" 1)

    (princ)
    );defun C:M2A
    ;;;=========================================================================
    =========
    ;;;Define Error Trap
    ;;;=========================================================================
    =========

    (defun opperr (s)

    (if (/= s "Function cancelled")
    (princ (strcat "\nError: " s))
    );if

    (setq *error* olderr)
    (setvar "osmode" oudosmode)
    (setvar "orthomode" oom)
    (command "undo" "b"
    "layer" "m" laag ""
    "redrawall"
    );command

    );defun opperr



    ;;;=========================================================================
    =========
    (princ)
    ;;;End Area Lisp
    ;;;=========================================================================
    =========
    ;;;=========================================================================
    =========
     
    Pad, Oct 1, 2004
    #1
  2. Pad

    T.Willey Guest

    In this area you need to change one line.

    (setq oppm (/ opp 1)
    oppma (rtos oppm 2 3); <- change the 3 to the desirec decimal place you want, in you case you want it to be 1
    oppmat (strcat oppma "m")
    tekst (strcat "\nArea = " oppmat "2")
    );setq

    Tim
     
    T.Willey, Oct 1, 2004
    #2
  3. Pad

    Pad Guest

    ah thanks
    i thought i had tried that already
    but it works so many thanks Tim


    want, in you case you want it to be 1
     
    Pad, Oct 1, 2004
    #3
  4. Pad

    T.Willey Guest

    Your welcome.
    =D

    Tim
     
    T.Willey, Oct 1, 2004
    #4
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.