Jump to content

Lisp Program to make regions and find area


arulmozhi

Recommended Posts

I am beginner to lisp. I'm in need of a program to calculate and print areas of undefined regions. So I want a lisp program to make region, calculate area and print the area with required decimal places wherever we want in the drawing area. Please help and post some lisp routines.

Link to comment
Share on other sites

Here's one I use to annotate lot areas; I revised it to create a region. Hopefully you can use parts of the code for your use.

;Labels a lot's area using the Boundary command. LPS 2008-10


(defun c:LA () ;(/ cl txtst txtsz oldecho oldsnap B ac sf kw)
 (setq temperr *error*);store *error*
 (setq *error* errortrap);reassign *error*
 (setq    cl    (getvar "clayer")
   txtst (getvar "textstyle")
   txtsz (getvar "textsize")
   oldecho (getvar "cmdecho")
   oldsnap (getvar "osmode")
 );setq
 (setvar "cmdecho" 0)
 (command "-style" "SIMPLEX" "simplex.shx" "0"    "0.9" "0" "n" "n" "n")
 (setq ip (getpoint "\nPick internal point: "))
 (command "-layer" "m" "calc" "c" "63" "calc" "p" "n" "calc" "")
 (command "-boundary" ip "")
 (command "region" (entlast) "")
 (setq b (entlast))
 (command "area" "o" b)
 (setq ac (strcat (rtos (/ (getvar "area") 43560) 2 3) " ACRES"))
 (setq sf (strcat (rtos (getvar "area") 2 2) " SQ.FT."))
 (command "-layer" "m" "LOT-AREA" "c" "53" "" "")
 (command "text"
      "s"
      "simplex"
      "c"
      ip
      (* 0.12 (getvar "dimscale"))
      "0"
      sf
 )                
 (command "text" "" ac)    
 (initget "Yes No")
 (setq kw (getkword "\nErase boundary Yes/No? <Yes>"))
 (if
   (= kw nil)
    (command "erase" b "")
 )                    ;if
 (command "textstyle" txtst)
 (setvar "clayer" cl)
 (setvar "textsize" txtsz)
 (setvar "cmdecho" oldecho)
 (setvar "osmode" oldsnap)
 (setq *error* temperr)
 (princ)
);defun c:

;==========ERROR TRAP=================
(defun errortrap (msg)                    ;define function
       (setvar "textstyle" txtst)
   (setvar "textsize" txtsz)
     (setvar "clayer" cl)
   (setvar "cmdecho" oldecho)                     ;restore variables
   (setvar "osmode" oldsnap)            
   (setq *error* temperr)            ;restore *error*
   (prompt "\nResetting System Variables ")    ;inform user
  (princ)
);defun
;==========ERROR TRAP=================

(prompt "\nLotArea.lsp loaded, type LA to run")
(princ)

Link to comment
Share on other sites

Thank you. It works pretty well. Still I need some more help to fulfil my task. Please change the code to give areas in square meteres with 3 decimal places. Further I need to make a table in Excel using different parts of the drawing. Therefore please make some code to put the areas in specified cells of mentioned excel sheets.

Link to comment
Share on other sites

Hint:

Look in Developer's Help for

(rtos... real to string

(open... open or create file. make it a .csv for excel

(write-line... write lines to the open file

Link to comment
Share on other sites

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.
Note: Your post will require moderator approval before it will be visible.

Guest
Unfortunately, your content contains terms that we do not allow. Please edit your content to remove the highlighted words below.
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...