brawleyman Posted January 5, 2009 Posted January 5, 2009 I am looking for a simple routine that can remember your last input. My current routine right now says "Enter drop distance to add to total length", so I have to enter the number each time. I would like for it to be able to remember what the last input was and say it after the "enter drop distance" statement then right click to apply it to continue the routine. I would like for it say something like this: Enter drop distance to add to total length : Where the 10 is, it needs to be whatever the last input is, whether it is 10 or 15 or whatever. Is there a way to do it? Thanks! Quote
Lee Mac Posted January 5, 2009 Posted January 5, 2009 There is indeed - take a look at this: http://www.cadtutor.net/forum/showthread.php?t=30948 Quote
Lee Mac Posted January 5, 2009 Posted January 5, 2009 ASMI's example is a good one, but I like to use setenv so that the LISP remembers the value even after it has completed. Quote
brawleyman Posted January 5, 2009 Author Posted January 5, 2009 LeeMac, Here is my code that I have been working on that you have helped me a few times on: (defun c:dis () (setvar "CMDECHO" 0) (setq num 1) (setq drop (getint "\nEnter drop distance to add to total length <**[i]*[/i][b][i]this is where I want the last distance[/i] [i]displayed[/i][/b][i]***[/i]>: ")) (setq drop (* 12 drop)) (setq pt (getpoint "\nSelect path to next device:")) (setq x1 (car pt)) (setq y1 (cadr pt)) (setq lensum (+ drop)) (while (setq pt (getpoint pt)) (setq x2 (car pt)) (setq y2 (cadr pt)) (setq xdiff (abs (- x1 x2))) (setq ydiff (abs (- y1 y2))) (setq len (+ xdiff ydiff)) (setq lensum (+ len lensum)) (setq segsum (strcat "---> TOTAL LENGTH: " (rtos (/ lensum 12) 2 0))) (setq x1 x2)(setq y1 y2) ) (princ "\n")(princ segsum) (princ) ) Most of the time, I use 10 for my 10ft drop distance. However, sometimes a project has to have 15ft or 20ft drop distances to each device. I would just like to have it so that when I first open a drawing and use this lisp, I type in 10 (or whatever the standard will be) the first time to get my distance, then after that, I can just right click (or enter) and it automatically applies that number each time without having to type it in every time. I am still trying to read and understand lisp, so I cannot pick out the little parts that I need to make this work. Thanks LeeMac! Quote
Lee Mac Posted January 5, 2009 Posted January 5, 2009 Try this: (defun c:dis (/ num drop pt x1 y1 lensum x2 y2 xdiff ydiff len segsum) (setvar "CMDECHO" 0) (setq num 1) (or (getenv "DROP:DIST") (setenv "DROP:DIST" "0")) (if (setq drop (getint (strcat "\nEnter drop distance to add to total length <" (getenv "DROP:DIST") "> :" ) ;_ end strcat ) ;_ end getint ) ;_ end setq (setenv "DROP:DIST" (rtos drop)) ) ;_ end if (setq drop (* 12 (atof (getenv "DROP:DIST")))) (setq pt (getpoint "\nSelect path to next device:")) (setq x1 (car pt)) (setq y1 (cadr pt)) (setq lensum (+ drop)) (while (setq pt (getpoint pt)) (setq x2 (car pt)) (setq y2 (cadr pt)) (setq xdiff (abs (- x1 x2))) (setq ydiff (abs (- y1 y2))) (setq len (+ xdiff ydiff)) (setq lensum (+ len lensum)) (setq segsum (strcat "---> TOTAL LENGTH: " (rtos (/ lensum 12) 2 0))) (setq x1 x2) (setq y1 y2) ) ;_ end while (princ "\n") (princ segsum) (princ) ) ;_ end defun Quote
brawleyman Posted January 5, 2009 Author Posted January 5, 2009 Try this: (defun c:dis (/ num drop pt x1 y1 lensum x2 y2 xdiff ydiff len segsum) (setvar "CMDECHO" 0) (setq num 1) (or (getenv "DROP:DIST") (setenv "DROP:DIST" "0")) (if (setq drop (getint (strcat "\nEnter drop distance to add to total length <" (getenv "DROP:DIST") "> :" ) ;_ end strcat ) ;_ end getint ) ;_ end setq (setenv "DROP:DIST" (rtos drop)) ) ;_ end if (setq drop (* 12 (atof (getenv "DROP:DIST")))) (setq pt (getpoint "\nSelect path to next device:")) (setq x1 (car pt)) (setq y1 (cadr pt)) (setq lensum (+ drop)) (while (setq pt (getpoint pt)) (setq x2 (car pt)) (setq y2 (cadr pt)) (setq xdiff (abs (- x1 x2))) (setq ydiff (abs (- y1 y2))) (setq len (+ xdiff ydiff)) (setq lensum (+ len lensum)) (setq segsum (strcat "---> TOTAL LENGTH: " (rtos (/ lensum 12) 2 0))) (setq x1 x2) (setq y1 y2) ) ;_ end while (princ "\n") (princ segsum) (princ) ) ;_ end defun Not quite working the way I need it to. I have it originally set up so that I can just put in "10" and it converts it to 10ft. The one that you just gave me only allows me to type in inches, I cannot type 10' because it requires an integer. Can it be set up so that I can just type 10 and it converts to 10 feet? Thanks! Quote
brawleyman Posted January 5, 2009 Author Posted January 5, 2009 Okay, here is the final product! I tested it and retested it to make sure that the dimensions add up. ;This function will calculate the distance a length of wire travels, at right angles, from one device to the next. (defun c:dis () (setvar "CMDECHO" 0) (setq num 1) (or (getenv "DROP:DIST") (setenv "DROP:DIST" "10")) (if (setq drop (getint (strcat "\nEnter drop distance to add to total length <"(getenv "DROP:DIST")">: "))) (setenv "DROP:DIST" (rtos (* 12 drop))) ) (setq drop (* 12 (atof (getenv "DROP:DIST")))) (setq pt (getpoint "\nSelect path to next device:")) (setq x1 (car pt)) (setq y1 (cadr pt)) (setq lensum (+ drop)) (while (setq pt (getpoint pt)) (setq x2 (car pt)) (setq y2 (cadr pt)) (setq xdiff (abs (- x1 x2))) (setq ydiff (abs (- y1 y2))) (setq len (+ xdiff ydiff)) (setq lensum (+ len lensum)) (setq segsum (strcat "---> TOTAL LENGTH: " (rtos (/ lensum 12) 2 0))) (setq x1 x2) (setq y1 y2) ) (princ "\n")(princ segsum) (princ) ) This LISP routine works great for anyone that has to calculate wire travel distances and have to include drop distance (for us, our wiring runs in the ceiling then drops 5ft to the device and back up 5ft to the conduit, hence the 10ft I keep talking about). Our wiring layout always runs in ortho or XY coordinates, which this routine calculates just that, so you can click on 2 devices spaced apart in an "L" shape and it gets that distance instead of a straight line from one to the other. Props to Lee Mac for helping me out and getting it to the point that I was wanting. Thanks! I hope that this routine can help someone else out as well. Oh, and if anyone is interested, I have a LISP I created that draws conduit lines in X and Y coordinates only and fillets the edge to whatever you want, you just have to set the fillet before you use it. It can also draw conduit in an "N" formation. Quote
Lee Mac Posted January 5, 2009 Posted January 5, 2009 Nice one Brawleyman, glad you could get it working Quote
BIGAL Posted January 6, 2009 Posted January 6, 2009 Rather than setenv why not just check if a value exists ? (if (= dropdist nil) (setq dropdist 10.0)) at top of code maybe even outside defun Once you change dropdist it will remain for entire session. You then check "drop" each time if its nil or 0.0 you pressed "enter key" dropdist is what you have set say 10 then it does not change dropdist value else uses new value. eg (setq insul_ht (getint "\nEnter Insulation ht mm : ")) (if (= insul_ht nil) (setq insul_ht 90) ) Quote
Lee Mac Posted January 6, 2009 Posted January 6, 2009 Hi BigAL, thanks for your suggestion I used setenv because it will hold its value. 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.