Jump to content

Get Stored value of a Variable as default in next preceding step


Recommended Posts

Posted

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 ?

Posted

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*)
  )
)

Posted
:D Thank you, @Tharwat, you really saved my day :thumbsup:
Posted
:D Thank you, @Tharwat, you really saved my day :thumbsup:

 

You're very welcome :)

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

Posted
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 ?

Posted

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.

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

Posted

Yeah ! that's better and thanks alot :D

Posted
Yeah ! that's better and thanks alot :D

 

You're very welcome :thumbsup:

 

Be informed that you can use the same function for the second input as shown into your first post which means tow in one ;)

Posted

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

Posted

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

Posted

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.

Posted
I checked that before coming to this forum and couldn't understand it at all

 

Great Facepalm.gif

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