TheSwamp

Code Red => AutoLISP (Vanilla / Visual) => Topic started by: daron on March 14, 2005, 12:58:04 PM

Title: ft or inches
Post by: daron on March 14, 2005, 12:58:04 PM
I just can't think of how to do this:
I want to ask a user for an input of a number and allow them to supply inches or feet and have lisp know the difference. I just can't think of how to do it. Anybody got any ideas. Seems like it shouldn't be too hard.
Title: ft or inches
Post by: MP on March 14, 2005, 01:03:17 PM
Use getstring and then distof.
Title: ft or inches
Post by: CAB on March 14, 2005, 01:09:11 PM
Use the getdist function.
Title: ft or inches
Post by: daron on March 14, 2005, 01:19:02 PM
Thank you.
Title: ft or inches
Post by: MP on March 14, 2005, 01:19:46 PM
Hey Charles, try this --

(setvar "lunits" 2)
(getdist) [enter] 12' [enter]

*shladdap*, rake in the face. :(

Subtitle: Getdist's ability to accept keyed input is a function of the lunits sys var setting.
Title: ft or inches
Post by: daron on March 14, 2005, 01:23:52 PM
CAB, that is what I was looking for. I knew it was there, I just needed to try it. Of course, I'll have to take MP's above thought to test.
Title: ft or inches
Post by: CAB on March 14, 2005, 02:04:39 PM
Quote from: MP
Hey Charles, try this --

(setvar "lunits" 2)
(getdist) [enter] 12' [enter]

*shladdap*, rake in the face. :(

Subtitle: Getdist's ability to accept keyed input is a function of the lunits sys var setting.
:?:
Why would you press [enter] before your 12'?

What happens with
(getstring) [enter] 12' [enter] :)

I was thinking getdist because it will allow many format options for user input.
Title: ft or inches
Post by: daron on March 14, 2005, 02:48:34 PM
Here's the solution to MP's problem:
Code: [Select]
(if (or (< (getvar 'lunits) 3) (> (getvar 'lunits) 4))
    (setq lunitnum (getvar 'lunits))
    (setvar 'lunits 4)
   )
(setq height (getdist "\nHeight of Wall: "))
(setvar 'lunits lunitnum)


Note: Any value other than 3 or 4 will result in the inability to use the ft (') mark.
Title: ft or inches
Post by: CAB on March 14, 2005, 02:59:11 PM
Oh, I see now. The fog is starting to lift.
Sorry Michael, as usual your reply went right over my pointy little head. :oops:
Title: ft or inches
Post by: MP on March 14, 2005, 03:17:27 PM
No worries Charles. You correctly pointed out the use of getdist; I just pointed out one mustn't make assumptions about its behavior. :)

And now for something completely different:

Code: [Select]
(defun distanceof ( x  / result )
    (vl-catch-all-apply
       '(lambda ()
            (vl-some
               '(lambda (units) (setq result (distof x units)))
                (list (getvar "lunits") 4 5 2 1)
            )
        )
    )    
    result
)


:)
Title: ft or inches
Post by: Mark on March 14, 2005, 03:43:03 PM
That's is a thing of beauty Michael.
Title: ft or inches
Post by: MP on March 14, 2005, 04:17:39 PM
Thank you Mark, meant to be (primarilly) demonstrative. :)