TheSwamp

Code Red => AutoLISP (Vanilla / Visual) => Topic started by: KewlToyZ on October 23, 2008, 01:50:27 PM

Title: Round to nearest foot?
Post by: KewlToyZ on October 23, 2008, 01:50:27 PM
(setq x 17.5)
(setq fmtval (rtos x 4 2))     ; Mode 4 = architectural
(princ (strcat str fmtval))    ; displays  Value formatted as 1'-5 1/2"

    (setvar "unitmode" 0)
    (setvar "LUPREC" 0)
    (setvar "DIMRND" 1)
    (setvar "DIMDEC" 0)

How do I get rtos to round to the nearest foot for output?
Is this a variable I am missing?
Title: Re: Round to nearest foot?
Post by: CAB on October 23, 2008, 02:36:33 PM
Use Kerrys function
Code: [Select]
;;* kdub:roundNearest (numVal roundTo Mode displayPrecision)
;; Round a numeric positive number to the NEAREST 'rounded' number
;; and format to n digits
;; kwb@theSwamp 20070814
;;  20081023 CAB added Mode
(DEFUN kdub:roundNearest (numVal roundTo Mode displayPrecision / remNum)
    (SETQ remNum (REM numVal roundTo))
    (RTOS (IF (>= (* 2 remNum) roundTo)
              (+ numVal (- roundTo remNum))
              (- numVal remNum)
          )
          Mode
          displayPrecision
    )
)

Code: [Select]
(kdub:roundNearest 17.5 12 4 0)
"1'-0\""
Title: Re: Round to nearest foot?
Post by: KewlToyZ on October 23, 2008, 06:14:41 PM
Thanks CAB   8-)
Title: Re: Round to nearest foot?
Post by: CAB on October 23, 2008, 07:09:52 PM
Glad to help & thanks to Kerry. 8-)

http://www.theswamp.org/index.php?topic=18695.0
Title: Re: Round to nearest foot?
Post by: Kerry on October 23, 2008, 07:55:01 PM
Nice adaptation Alan .. I tend to ignore that some of the world still uses inches and feet. ( though I still thing in both occasionally for non technical stuff ... :) )
Title: Re: Round to nearest foot?
Post by: CAB on October 23, 2008, 09:01:18 PM
All of My World uses feet & inched. 8-)
Title: Re: Round to nearest foot?
Post by: KewlToyZ on October 28, 2008, 04:33:59 PM
I ended up adapting it differently for the setup I was doing using the files attached.
Mainly I was trying to make something generic for creating engineering spaces.
When I get time I was thinking of adding a block insert to create a small Engineering Space numeric bubble and a routine at the end to autoincrement the attribute tag so notes can be assigned.
Its still a pretty hokey adaption of what the guys on the swamp here made but it works. :wink: