Jump to content

Recommended Posts

Posted

Hi,

I have no idea about lisp routines, and have been doing my head in trying to learn. I am hoping someone here may be happy to help me write one.

Firstly I work for a surveyor and have to calculate unit areas for a strata plans. We always round the area down, so a unit with an internal area of 28.8 would be called 28 + a balcony of 7.2 (called 7) + a carspace 13.6 (13), (so 28 + 7 + 13)

I use polygons to create the area and always add a field for the surveyor to check.

What I'd like is a lisp routine where I can - pick & add the polygons for each lot, having the areas rounded down for each polygon I pick.

 

I found the below code on Acad discussions which I think should be a good starting point, but am lost from here

 

(defun C:AA ()

(setq Aobject (car (entsel "\nSelect area polyline: ")))

(if (equal (vlax-curve-getStartPoint Aobject) (vlax-curve-getEndPoint Aobject) 1e-8)

(progn ; then

(command "area" "e" Aobject)

(setq Tarea (rtos (/ (getvar "area") 1000000.0) 2 0))

(setq Totalarea (strcat Tarea "sqm"))

(alert Totalarea)

); end progn

(alert "Polyline is not closed."); else

); end if

(princ)

); end defun

{code}

Posted

Why would you round an area of 28.8 down to 28??? I understand with land management it shouldn't be rounded up per say, although why not to 28.5?

Posted

may be needed

;;Rounding By John W. Anstaett
;;use (rounding mynumber roundto offset)
;;mynumber this is the number you need to round off
;;Roundto is the number to roundto
;;offset set to 0 will roundto to next lower number
;;offset set to 1 will next higher number
;;offset set to 0.5 will be to nerest number
;;exp (rounding 12.1 5 1)  return 15
;;exp (rounding 12.1 5 0) return 10
;;exp (rounding 12.49 5 0.5) reutne 10
;;exp (rounding 12.5 5 0.5) return 15
;; exp (rounding 0.68 0.25 0.5) return 0.75

(defun rounding  (mynumber roundto offset)
 (setq temp
 (*(fix  (+ (/ mynumber roundto) offset )) roundto)
)
 )

Use

(rounding 28.8 1 0) ;_-> 28

(rounding 28.8 0.5 0) ;_->28.5

Posted

These may help:

 

http://lee-mac.com/totallengthandarea.html

 

As for Rounding:

 

(defun LM:Round ( n ) (fix (+ n (/ n (abs n) 2.))))

(defun LM:Roundto ( n p ) (/ (fix (+ (* n (setq p (expt 10. p))) (/ n (abs n) 2.))) p))

Examples:

 

_$ (LM:Round 2.6)
3
_$ (LM:Round 2.4)
2
_$ (LM:Roundto 2.62571 1)
2.6
_$ (LM:Roundto 2.62571 2)
2.63
_$ (LM:Roundto 2.62571 3)
2.626
_$ (LM:Roundto 2.62571 4)
2.6257
_$ (LM:Roundto 2.62571 5)
2.62571

 

Or to get the largest Integer less than the Area, use fix as Alan suggests.

[url=http://lee-mac.com/totallengthandarea.html][/url]

Posted

Also, you could float the returned value for the LM:Round routine, if you wanted a real instead of an integer.

 

or

 

(defun LM:Round ( n ) (float (fix (+ n (/ n (abs n) 2.)))))

Posted

Thanks for your replies. Will have a play and hopefully get something working

 

As far as the round down thing, we only use whole numbers no .5's and we round down mainly because people use the plans we do to sell the apartments, and it's better to tell someone their buying 28m2 internal and have them get more, then say your buying 29 & it's actually less.

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...