jmerch Posted December 30, 2010 Posted December 30, 2010 I've created a simple lisp that stretches certain objects to a given height above finished floor. Now I feel it would be better used if it would also allow the user to enter a different height above the floor than what I set. I can't find anything on this. What I want is when the user initiates the command it says "Current Stub Up Height is " where X is the default value. so it either continues with the command if the user proceeds and clicks a point in CAD, or if they don't and just type a new number in, then enter, then continues with command. Make sense? Here's the original lisp where it asks the user to enter the height, like I said it's simple. ;;; === Stretch Stub - User Input === ;;; Asks user for height in inches above finished floor to stretch stub ;;; Copyright 2010 Josh Merchant (defun c:sta (/) (setq coord "@0,0,") (setq height (getstring T"\nEnter stub up height in inches AFF:")) (command "stretch" "c" pause pause "" "node" pause "from" ".z" "0,0,0" "0,0,0" (strcat coord height)) (princ) ) Quote
Lee Mac Posted December 30, 2010 Posted December 30, 2010 Thanks Hasan JMerch, I would recommend you use getdist to obtain your 'stub up height', then convert this numerical value to a string should you want to concatenate it with your 'coord' variable. Quote
jmerch Posted December 30, 2010 Author Posted December 30, 2010 asos, Thanks for the link...I don't know what I was thinking not going to Lee's site before I asked a question . Lee, First thanks for the tutorial on your site. Now to the point at hand. Looking at your last example, I feel that is the route i need to take (still using the getint). That being said, I can't get my strcat to read the *ans*. I also re-did it with getdist and still can't get it to read it. (defun c:sta (/) (setq coord "@0,0,") (setq *ans* (cond ( (getint (strcat "\nSpecify Stub Up Height <" (itoa (setq *ans* (cond ( *ans* ) ( 8 )) ) ) ">: " ) ) ) ( *ans* ) ) ) (princ) (command "stretch" "c" pause pause "" "node" pause "from" ".z" "0,0,0" "0,0,0" (strcat coord *ans*)) ) Quote
Lee Mac Posted December 30, 2010 Posted December 30, 2010 You're welcome JMerch Hint: think about what datatype is held by the variable '*ans*', and what is held by 'coord'. Quote
jmerch Posted December 30, 2010 Author Posted December 30, 2010 Hint: think about what datatype is held by the variable '*ans*', and what is held by 'coord'. Ok, so originally I thought taking the itoa was the answer, but it's not. I changed the getint to getstring and also tried another way of just doing (strcat "@0,0," *ans*). The former worked. Now, I've been staring and studying your tutorial very hard this afternoon (my eyes are straining and brain is not soaking in anymore information) and can't see how to make 8 the default to where the user can just right click or hit enter after the "Enter Stub Up Height" comes up. (defun c:sta (/) (setq coord "@0,0,") (setq *ans* (cond ( (getstring (strcat "\nEnter Stub Up Height <" (setq *ans* (cond ( *ans* ) ( 8 )) ) ">: " ) ) ) ( *ans* ) ) ) (princ) (command "stretch" "c" pause pause "" "node" pause "from" ".z" "0,0,0" "0,0,0" (strcat coord *ans*)) ) Quote
pBe Posted December 31, 2010 Posted December 31, 2010 getstring---> "8" getint ------> 8 command: (setq x (getint)) nil command: (setq x (getstring)) "" Quote
Lee Mac Posted December 31, 2010 Posted December 31, 2010 If you wanted to use getint, you need to bear in mind that the variable *ans* is holding an integer. Should you want to proceed with the method of concatenating this with the 'coord' string, a conversion is required: (defun c:sta ( / coord ) (setq coord "@0,0,") (setq *ans* (cond ( (getint (strcat "\nSpecify Stub Up Height <" (itoa (setq *ans* (cond ( *ans* ) ( 8 )) ) ) ">: " ) ) ) ( *ans* ) ) ) (command "stretch" "c" pause pause "" "node" pause "from" ".z" "0,0,0" "0,0,0" (strcat coord [color=blue]([/color][color=red][b]itoa[/b] [/color]*ans*[color=blue])[/color])) (princ) ) This may seem a little redundant, as you might say - 'why not just store *ans* as a string?' - then no conversion is needed in the prompt/command. But, when prompting for an integer, it seems more logical to me to store the default as an integer. In this situation, I would be inclined to use getdist however: (defun c:sta ( / coord ) (setq coord "@0,0,") (setq *ans* (cond ( ([b][color=red]getdist[/color][/b] (strcat "\nSpecify Stub Up Height <" ([b][color=red]rtos[/color][/b] (setq *ans* (cond ( *ans* ) ( 8.0 )) ) ) ">: " ) ) ) ( *ans* ) ) ) (command "stretch" "c" pause pause "" "node" pause "from" ".z" "0,0,0" "0,0,0" (strcat coord [color=blue]([/color][b][color=red]rtos[/color][/b] *ans*[color=blue])[/color])) (princ) ) Everybody gets one Quote
pBe Posted December 31, 2010 Posted December 31, 2010 so you gave in Lee, for a while there I thought you're content with just giving hints Happy New Year my friend Quote
Lee Mac Posted December 31, 2010 Posted December 31, 2010 so you gave in Lee, for a while there I thought you're content with just giving hints Indeed, I couldn't let him suffer any longer Happy New Year my friend And to you too Quote
jmerch Posted December 31, 2010 Author Posted December 31, 2010 Ahh....didn't think about putting the itoa in front of the *ans* in the last strcat. I assumed it converted it during the first one but i think I see why it's needed now. I'll be honest with you, I'm not familiar with itoa, or rtos, or even my brain trying to think about if I should use real numbers, integers, strings, getdist, etc. I'm slowly getting there. I do appreciate all the help from you guys regardless of how much it seems I suffer Happy New Year to you. Quote
irneb Posted January 3, 2011 Posted January 3, 2011 I'd also advise as per Lee: for this case getdist would be the most logical. It would even allow the user to pick the distance between 2 points instead of typing it in. The reason you usually use getdist / getint / etc. as opposed to getstring is that they already test for certain conditions such as the user can only enter numbers - no need to then have some extra code to check for this as well. And then since the result is a real, you can do regular arithmetic with it to the maximum precision possible. If you constantly need to convert to-and-from string, you can very easily loose huge chunks of precision due to rounding errors. Therefore the rule of thumb is: keep numbers in their number form, convert them to text only when needed - don't re-use the text somewhere else (rather just convert again). Quote
Recommended Posts
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.