Jump to content

save getxxx previous value


Aditya Bagaskara

Recommended Posts

How do I save the previous getxxx value that i just inserted so I don't have to type them again? (Example in offset command that the previous offset distance is saved)

Link to comment
Share on other sites

Save it as a global variable:

 

(

(defun c:test ()
    (setq *your_global_variable*
        (cond
            ((getdist (strcat "\nSpecify distance" (if *your_global_variable* (strcat " <" (rtos *your_global_variable* 2 3) ">") "") ": ")))
            (*your_global_variable*)
        )
    )
)

 

  • Like 2
Link to comment
Share on other sites

1 hour ago, Jonathan Handojo said:

Save it as a global variable:

 

(

(defun c:test ()
    (setq *your_global_variable*
        (cond
            ((getdist (strcat "\nSpecify distance" (if *your_global_variable* (strcat " <" (rtos *your_global_variable* 2 3) ">") "") ": ")))
            (*your_global_variable*)
        )
    )
)

 

I knew it!!!! It somehow involves angle brackets. Thanks for the help!! :)

Link to comment
Share on other sites

3 hours ago, Jonathan Handojo said:

Save it as a global variable:

 

(

(defun c:test ()
    (setq *your_global_variable*
        (cond
            ((getdist (strcat "\nSpecify distance" (if *your_global_variable* (strcat " <" (rtos *your_global_variable* 2 3) ">") "") ": ")))
            (*your_global_variable*)
        )
    )
)

 

Can you explain line by line of how this works? Thank you
Wait nevermind I think I got how this works, I'll type it soon

Edited by Aditya Bagaskara
Link to comment
Share on other sites

So, I have shortened the command into this one below and somehow still worked:

(defun c:test ()
    (setq *your_global_variable*
	   (getdist (strcat "\nSpecify distance" (if *your_global_variable* (strcat " <" (rtos *your_global_variable* 2 3) ">") "") ": "))
    )
)

The explanation is:
- *your_global_variable* has not been defined. 
- The way to defining it is to use the getdist function.

- The neat part is the if function. It checks if *your_global_variable* has been defined or not:

     - If not, it will yield nothing.

     - If it has been defined, it will yield the previous value.

       I just learned that how to insert a default value is to use angle brackets.

- After the getdist has returend a value, then the value is inserted to *your_global_variable*, ready to be used again.

Please correct my explanation as this is just merely my speculation 🙏🏻🙏🏻 @Jonathan Handojo

Link to comment
Share on other sites

You are almost correct. In your rectification above, the global variable will be set to nil if the user presses Enter without giving a distance.

 

The purpose of the cond function is to justify the default value that was previously stored. In my code snippet, the cond function will put in whatever value the user inputs (if the user actually does input something in). Otherwise, getdist then returns nil, and the cond function proceeds into the second line and inserts the default variable.

 

In your snippet, you managed to get your message prompt right. However, remember that, just because the prompt simply alerts the user the default value using <> doesn't mean that getdist acually returns that value. You still need to use if conditions to account for this.

  • Like 1
Link to comment
Share on other sites

4 hours ago, Jonathan Handojo said:

You are almost correct. In your rectification above, the global variable will be set to nil if the user presses Enter without giving a distance.

 

The purpose of the cond function is to justify the default value that was previously stored. In my code snippet, the cond function will put in whatever value the user inputs (if the user actually does input something in). Otherwise, getdist then returns nil, and the cond function proceeds into the second line and inserts the default variable.

 

In your snippet, you managed to get your message prompt right. However, remember that, just because the prompt simply alerts the user the default value using <> doesn't mean that getdist acually returns that value. You still need to use if conditions to account for this.

Ah I see it now. I can't actually get the previous value by pressing Enter or Space because there's no function to do so. The cond makes it possible to choose whether I can define new value or use previous value. Made me learn that the t (default expression) can be executed by pressing Enter or Space (probably because they yield nil).
Very clever :D Thanks for the help!!

Edited by Aditya Bagaskara
Link to comment
Share on other sites

3 hours ago, Aditya Bagaskara said:

Do you know how to hide the lines inside the angle brackets while executing the command in AutoCAD? @Jonathan Handojo

What do you mean by that?

Link to comment
Share on other sites

39 minutes ago, Jonathan Handojo said:

What do you mean by that?

"Specify the distance <...>"

I want to hide the <...> part. It showed up at the getxxx message.

Link to comment
Share on other sites

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