Author Topic: boundary command in lisp  (Read 4145 times)

0 Members and 2 Guests are viewing this topic.

wjbzone

  • Guest
boundary command in lisp
« on: October 15, 2008, 09:29:30 AM »
I am trying to write a lisp program to create an new boundary (polyline) and print the area for that boundary.
Can anyone help with this :

Code: [Select]
(defun c:ba ()
     (command "-boundary" pause)
     (set ent1 (entlast))
     (command ".area" "e" ENT1)
     (setq Area (getvar "area"))
     (setq Acre 43560)
(setq a (/ area acre))
(princ a)
(princ "  Acres     ")
(princ area)
)


Thanks,
Bill

Gliderider

  • Guest
Re: boundary command in lisp
« Reply #1 on: October 15, 2008, 10:01:09 AM »
Try this...
Code: [Select]
;;displays the areas of an enclosed area using the boundary command - LPS 2008

(defun c:ba (/ oldecho oldlayer ip ss sqft sqyd acres)
 
(setq temperr *error*) ;store *error*
(setq *error* errortrap) ;re-assign *error*
(setq oldlayer (getvar "clayer") ;store variables as needed
oldecho  (getvar "cmdecho")
  )
  (command "-layer" "m" "CALC" "p" "n" "" "")
  (setq ip (getpoint " Pick internal point: "))
  (command "-boundary" ip "")
  (setq ss (entlast))
  (command "area" "o" ss)
  (setq sqft  (getvar "area")
sqyd  (/ sqft 9)
acres (/ sqft 43560)
  )
  (alert
    (strcat "\n" (rtos sqft 2 2) " Square feet"
    "\n" (rtos sqyd 2 2) " Square yards"
    "\n" (rtos acres 2 3) " Acres"
     )
  )
   (initget "Yes No")
   (setq kw (getkword "\nErase boundary Yes/No? <Yes>"))
  (if
    (= kw nil)
     (entdel (entlast))
  ) ;if
  (setvar "clayer" oldlayer)
  (setvar "cmdecho" oldecho)
  (princ)
)


;======ERROR TRAP=======
; insert after defun c: closing parenthesis

(defun errortrap (msg) ;define function
        (setvar "clayer" oldlayer)
(setvar "cmdecho" oldecho)              ;restore variables
(setq *error* temperr) ;restore *error*
(prompt "\nResetting System Variables ") ;inform user
   (princ)
);defun
;======ERROR TRAP=======
« Last Edit: October 15, 2008, 10:43:18 AM by lpseifert »

wjbzone

  • Guest
Re: boundary command in lisp
« Reply #2 on: October 15, 2008, 11:19:07 AM »
Thanks lpseifert
That was a fast reply.
Here is my working (with your help) version:

Code: [Select]
;;Inserts Text showing area (acres) of polyline created using the Boundary command
; text insertion point at click

(defun c:ba ()
 (SETQ IP (GETPOINT " Pick Internal Point: "))
 (COMMAND "-BOUNDARY" ip "")
 (SETQ SS (ENTLAST))
 (PROGN (COMMAND "AREA" "o" SS)) 
  (SETQ acres (/ (GETVAR "AREA") 43560))
  (SETQ Acres (rndby acres 0.001))
(setq ktext (strcat (rtos acres 2 2)" Acres"  ))
     (setq ht 20)
  (command "_.text" ip ht "0" ktext)


    (princ)
)

(defun rndby (r b / tmp)
  (setq tmp (rem r b))
  (cond ((>= tmp (* 0.5 b))  (+ r (- b tmp)))
        (T                   (- r tmp))))