aridzv Posted January 9, 2023 Posted January 9, 2023 (edited) Hi. I found this thread about setting Default values for real number and used @lpseifert example (thanks...): (defun test (/ dist) (if (null *dist*) (setq *dist* 0.83) ) (setq dist (getreal (strcat "\n What is the offset distance?: <" (rtos *dist* 2 2) ">: ")) ) (if (not dist) (setq dist *dist*) (setq *dist* dist) ) (alert (strcat "\nThe value of *dist* is " (rtos *dist* 2 2) "\nThe value or dist is " (rtos dist 2 2))) ) and I found this thread about reading values from TXT file and used Lee mac code (thanks again...): (defun c:test ( / des str txt ) (cond ( (not (setq txt (findfile "map.txt"))) (princ "\nmap.txt not found.") ) ( (not (setq des (open txt "r"))) (princ "\nmap.txt could not be opened for reading.") ) ( (princ "\nmap.txt found and opened for reading.") (setq str (read-line des)) (princ "\nRead 1 line from map.txt: ") (princ str) (close des) (princ "\nmap.txt closed.") ) ) (textpage) (princ) ) I need help with setting *dist* to "str" that came from the file instand of the fix value of 0.83 (in this example). thanks, aridzv. *EDIT: O.K, after a little more digging - after the code that bring the data from the file: (setq str1 (atof str));; converting the string from the TXT file to real number ;; in the second code segment setting str1 to *dist* and CANCEL THE IF CONDITION (this ia what I was missing - if the if stay *dist* will be 0) ;;(if (null *dist*);; - CANCEL (setq *dist* str1) ;;);;close if;; -CANCEL Edited January 10, 2023 by aridzv Quote
mhupp Posted January 10, 2023 Posted January 10, 2023 (edited) Depends on whats in the text file. This lisp would make points listed in a text file. Each line was. <PointID> <Easting> <Northing> <Elevation> If all your getting is one value stick with prompts. this will save the variable Dist into the drawing file as ldata. When you run the command again it will remember last input. (or (setq *dist (vlax-ldata-get "Distance" "Dist")) (setq *dist 0.83)) (if (setq dist (getdist (strcat "\nSpecify Distance [" (rtos *dist 2 2) "]: "))) (vlax-ldata-put "Distance" "Dist" dist) ;updates with new distance (vlax-ldata-put "Distance" "Dist" (setq dist *dist)) ) Edited January 10, 2023 by mhupp 1 Quote
aridzv Posted January 10, 2023 Author Posted January 10, 2023 (edited) @mhupp many thanks for the reply!! I've looked on the vlax-ldata help function (get & put) documentation since it is new for me... I have one qeustion: what is the meaning of the (*) next to dist in the setq statments? thanks, aridzv Edited January 10, 2023 by aridzv Quote
mhupp Posted January 10, 2023 Posted January 10, 2023 Its just a 2nd variable. You could use x and y or whatever you want. You have to use two variables or the if statement would always be true. (or (setq x (vlax-ldata-get "Distance" "Dist")) (setq x 0.83)) (if (setq y (getdist (strcat "\nSpecify Distance [" (rtos x 2 2) "]: "))) (vlax-ldata-put "Distance" "Dist" y) ;updates with new distance (vlax-ldata-put "Distance" "Dist" (setq y x)) ) 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.