Aditya Bagaskara Posted February 20 Posted February 20 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) Quote
Jonathan Handojo Posted February 20 Posted February 20 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*) ) ) ) 2 Quote
Aditya Bagaskara Posted February 20 Author Posted February 20 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!! Quote
Aditya Bagaskara Posted February 20 Author Posted February 20 (edited) 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 February 20 by Aditya Bagaskara Quote
Aditya Bagaskara Posted February 20 Author Posted February 20 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 Quote
Jonathan Handojo Posted February 20 Posted February 20 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. 1 Quote
Lee Mac Posted February 20 Posted February 20 Perhaps this tutorial is helpful - https://lee-mac.com/promptwithdefault.html 1 Quote
Aditya Bagaskara Posted February 21 Author Posted February 21 (edited) 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 Thanks for the help!! Edited February 21 by Aditya Bagaskara Quote
Aditya Bagaskara Posted February 21 Author Posted February 21 1 hour ago, Lee Mac said: Perhaps this tutorial is helpful - https://lee-mac.com/promptwithdefault.html I admire you!!! You really have a nice tutorial page! It takes me a while to understand, though Quote
Aditya Bagaskara Posted February 21 Author Posted February 21 Do you know how to hide the lines inside the angle brackets while executing the command in AutoCAD? @Jonathan Handojo Quote
Jonathan Handojo Posted February 21 Posted February 21 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? Quote
Aditya Bagaskara Posted February 21 Author Posted February 21 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. 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.