Suresh968 Posted August 5, 2013 Posted August 5, 2013 I'm completely new to Autolisp. I've searched all over the internet and couldn't get it work:oops:. How'd I Get the previously Stored value of a Variable in next preceding step using autolisp ? e.g. (setq Hscl (getreal "Enter Horizontal Scale Factor H:")) (setq Vscl (getreal "Enter Vertical Scale Factor V:")) I've got the values for Hscl and Vscl with User Inputs. Say, I want to set the last Hscl and Vscl values as default for the next time when user repeats the command; then how'd I do it ? Quote
Tharwat Posted August 5, 2013 Posted August 5, 2013 Just an example to you to consider . (initget 6) (setq *Hscl* (cond ((getreal (strcat "\n Enter Horizontal Scale Factor H: <" (rtos (if *Hscl* *Hscl* (setq *Hscl* 1.0) ) ) ">: " ) ) ) (*Hscl*) ) ) Quote
Suresh968 Posted August 5, 2013 Author Posted August 5, 2013 Thank you, @Tharwat, you really saved my day Quote
Tharwat Posted August 5, 2013 Posted August 5, 2013 Thank you, @Tharwat, you really saved my day You're very welcome Quote
Suresh968 Posted August 5, 2013 Author Posted August 5, 2013 Just an example to you to consider . (initget 6) (setq *Hscl* (cond ((getreal (strcat "\n Enter Horizontal Scale Factor H: <" (rtos (if *Hscl* *Hscl* (setq *Hscl* 1.0) ) ) ">: " ) ) ) (*Hscl*) ) ) What about a little bit simpler; in case if any you might know. Though, I understood the first one and it works in my case. Quote
Tharwat Posted August 5, 2013 Posted August 5, 2013 What about a little bit simpler; in case if any you might know. Though, I understood the first one and it works in my case. I am sorry I didn't get you , can you be more specific to the point ? Quote
Suresh968 Posted August 5, 2013 Author Posted August 5, 2013 Sorry, if I bothered you. I only mean to say is it possible to use simple code instead of using condition as I am completely new to this. Quote
Tharwat Posted August 5, 2013 Posted August 5, 2013 Sorry, if I bothered you. No at all , I just want to know what you are after to try to give you the best I know I only mean to say is it possible to use simple code instead of using condition as I am completely new to this. You can wrap that long code ( as far as you didn't like it ) with a sub-function as following and call it with a simple line . (defun HorizontalScaleFactor (msg) ;; Tharwat 05. Aug. 2013 ;;; (initget 6) (setq *Hscl* (cond ((getreal (strcat "\n" msg " <" (rtos (if *Hscl* *Hscl* (setq *Hscl* 1.0) ) ) ">: " ) ) ) (*Hscl*) ) ) *Hscl* ) To call the above said function . (HORIZONTALSCALEFACTOR "Enter Horizontal Scale Factor H:") Hope this helps . Quote
Suresh968 Posted August 5, 2013 Author Posted August 5, 2013 Yeah ! that's better and thanks alot Quote
Tharwat Posted August 5, 2013 Posted August 5, 2013 Yeah ! that's better and thanks alot You're very welcome Be informed that you can use the same function for the second input as shown into your first post which means tow in one Quote
BIGAL Posted August 5, 2013 Posted August 5, 2013 Even simpler (if (= hscl nil) (setq Hscl (getreal "Enter Horizontal Scale Factor H:")) ) A 2nd example (if (= vert nil) (progn (setq vert 50) (prompt "\nEnter Vertical scale:<") (prin1 vert) (prompt ">:") (setq newvert (getint)) (if (= newvert nil) (setq vert vert) (setq vert newvert) ) ) ) Quote
hmsilva Posted August 5, 2013 Posted August 5, 2013 A different one, tests if the variable exists, and if a real number is assigned to the variable... (defun c:test (/ tmpH) (if (or (not *Hscl*) (/= (type *Hscl*) 'REAL)) (setq *Hscl* 1.0)) (initget 6) (setq tmpH (getreal (strcat "\nEnter Horizontal Scale Factor H <" (rtos *Hscl*)">: "))) (if (/= tmpH nil) (setq *Hscl* tmpH)) (princ) ) Henrique Quote
Suresh968 Posted August 6, 2013 Author Posted August 6, 2013 I appreciate your help. Thanks ! all of you. I've learned so much just in 1 day, because of you guys. Hats off ! This tutorial may be of interest. Yeah ! I checked that before coming to this forum and couldn't understand it at all but now I understand it just because of you guys explained it in a better & simpler way. Quote
Lee Mac Posted August 6, 2013 Posted August 6, 2013 I checked that before coming to this forum and couldn't understand it at all Great 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.