Cylis0509 Posted November 3, 2015 Posted November 3, 2015 Hi Guys, I have LISP that works great but I would like to take it to the next level. My LISP ask the user for a radius they would like to use. Then continues the command. I would love for the LISP to remember the user's last input if the command is used again later within the same session. Much like the offset command; when first used you specify the offset and finish the command. If you come back after doing say 20 other commands it remembers the last value used and shows it in brackets; , and the user just needs to hit enter to except, they don't have to re-enter the value again. I hope that makes sense... Could someone help teach me how to do this or at least point me in the right direction? Thank you in advance! Quote
satishrajdev Posted November 3, 2015 Posted November 3, 2015 (edited) Can you post your code here... So i can show you by editing it Example :- (setq a b) (setq b (getint (strcat "\nSpecify Radius " (if (not a) ": " (strcat "<" (itoa a) ">: ") ) ) ) ) (if (and (not b) a) (setq b a) ) Edited November 3, 2015 by satishrajdev Quote
lijinsong1972 Posted November 3, 2015 Posted November 3, 2015 (setvar "users1" offsetdistance) (atof(getvar "users1")) Quote
lijinsong1972 Posted November 3, 2015 Posted November 3, 2015 ;(setvar "users1" offsetdistance) ;(atof(getvar "users1")) (defun c:mj() (setq point1 (getpoint "\nselect point point2 (getpoint pt1"\nselect point distance (distance pt1 pt2 ) ) ;;save (setvar "USERS1" (rtos ds 2 1)) (command "move" (ssget)"" pause (atof(getvar "users1"))) ) Quote
Cylis0509 Posted November 3, 2015 Author Posted November 3, 2015 Can you post your code here... So i can show you by editing it Example :- (setq a b) (setq b (getint (strcat "\nSpecify Radius " (if (not a) ": " (strcat "<" (itoa a) ">: ") ) ) ) ) (if (and (not b) a) (setq b a) ) Thank you very much! I will give this a try. I would like to try to figure it out myself with the info you gave me first. (I learn better that way.) But if I get stuck I will defiantly post it and reach out to you again. Thank you again very much! Quote
Lee Mac Posted November 3, 2015 Posted November 3, 2015 This tutorial may be of some help: Prompting with a Default Option. 1 Quote
Cylis0509 Posted November 3, 2015 Author Posted November 3, 2015 This tutorial may be of some help: Prompting with a Default Option. Thank you Lee Mac this is great stuff!! Much appreciated! Quote
David Bethel Posted November 3, 2015 Posted November 3, 2015 I use a global variable prefix scenario to store info for later use: All variables with the prefix gv_ are global for that session only (setq xdef (if gv_xval gv_xval 100)) (setq x (getdist (strcat "\n X Axis Value <" (rtos xdef 2 2) ">: "))) (or x (setq x xdef)) (setq gv_xval x) To see the current settings of all gv_ variables : (defun c:gv (/ fl af) (setq af (reverse (acad_strlsort (atoms-family 1)))) (foreach a af (and (= "GV_" (strcase (substr a 1 3))) (setq fl (cons (cons a (eval (read a))) fl)))) (textpage) (princ "Global Variable Settings:") (foreach a fl (terpri) (prin1 a)) (prin1)) It's not unusual to have 10 -> 20 gv_ values set at any one time -David Quote
satishrajdev Posted November 3, 2015 Posted November 3, 2015 Thank you very much! I will give this a try. I would like to try to figure it out myself with the info you gave me first. (I learn better that way.) But if I get stuck I will defiantly post it and reach out to you again. Thank you again very much! Sure... No problem:thumbsup: Quote
Cylis0509 Posted November 3, 2015 Author Posted November 3, 2015 This tutorial may be of some help: Prompting with a Default Option. Lee Mac, It is great that you replied to this post because it's one of your LISPs I am trying to modify. Orginally the user asked me to modify it so he could specify the radius. So I did that for him. Now he wants the additional functionality I specified. I have read the link you sent me (which is great by the way) and I am having a problem, not sure I fully understand. It always reads not the last value entered. You will see that I commented out my original change (setq bDis (getreal "\n Enter new value for Jump Radius: ")) which did work. ;;; JMPR.lsp ;;; ;;; Description ;;; Jumper will auto-create the radius jump for pipe crossings. ;;; ;;; Author: Lee Mac (CADTutor) ;;; Date: 03/25/10 ;;; ;;; Revision: 1 ;;; Revision Date: 10/30/15 ;;; Description - Modified by David Prontnicki ;;; Added the ability to select your radius at the beginning of the command. ;;; Changed interface verbage ;;; ;;; Command: JMPR ;;; -----------------------------------------------------------------------------; (defun c:jmpr (/ *error* A AENT B1 B2 BDIS BENT DOC ENT OV P1 P2 UFLAG VL O W) ; (setq bDis (getreal "\n Enter new value for Jump Radius: ")) ; Modified by David Prontnicki (setq bDis (cond ( (getreal (strcat "\n Enter new value for Jump Radius <" (itoa (setq bDis (cond ( bDis ) (1) ) ) ) ">: " ) ) ) ( bDis ) ) ) (defun *error* (msg) (and uFlag (vla-EndUndoMark doc)) (and ov (mapcar (function setvar) vl ov)) (and msg (or (wcmatch (strcase msg) "*BREAK,*CANCEL*,*EXIT*") (princ (strcat "\n** Error: " msg " **")))) (princ)) (setq doc (vla-get-ActiveDocument (vlax-get-acad-object)) vl '("PEDITACCEPT" "CMDECHO" "OSMODE") ov (mapcar (function getvar) vl)) (setvar "PEDITACCEPT" 1) (while (and (setq uFlag (not (vla-StartUndoMark doc))) (mapcar (function setvar) (cdr vl) '(0 32)) (setq p1 (getpoint "\nPick the crossing intersection: ")) ; Modified by David Prontnicki (setq ent (entsel "\nSelect the line to break: "))) ; Modified by David Prontnicki (setq p2 (osnap (cadr ent) "_nea") b1 (polar p1 (setq a (angle p1 p2)) bDis) b2 (polar p1 (+ pi a) bDis)) (setvar "OSMODE" 0) (command "_.break" b1 b2) (setq bEnt (entlast)) (if (> a (/ pi 2.)) (command "_.arc" b2 "_E" b1 "_A" 180.) (command "_.arc" b1 "_E" b2 "_A" 180.)) (setq aEnt (entlast)) (if (eq "LWPOLYLINE" (cdr (assoc 0 (entget (setq ent (car ent)))))) (progn (setq w (vla-get-ConstantWidth (setq o (vlax-ename->vla-object ent)))) (command "_.pedit" "_M" bEnt aEnt ent "" "_J" "" "") (vla-put-ConstantWidth (vlax-ename->vla-object (entlast)) w))) (setq uFlag (vla-EndUndoMark doc))) (*error* nil) (princ)) Any help would be greatly appreciated. Thank you in advance. Quote
Cylis0509 Posted November 3, 2015 Author Posted November 3, 2015 Sure... No problem:thumbsup: Satishrajdev, So I tried appling your approach and it does not seem to be working for me, and I am 100% positive its because I'm not doing right. You will see that I have commented out my original piece of code requesting the radius and ATTEMPED your approach. I'm obviously not doing something right... ;;; JMPR.lsp ;;; ;;; Description ;;; Jumper will auto-create the radius jump for pipe crossings. ;;; ;;; Author: Lee Mac (CADTutor) ;;; Date: 03/25/10 ;;; ;;; Revision: 1 ;;; Revision Date: 10/30/15 ;;; Description - Modified by David Prontnicki ;;; Added the ability to select your radius at the beginning of the command. ;;; Changed interface verbage ;;; ;;; Command: JMPR ;;; -----------------------------------------------------------------------------; (defun c:jmpr (/ *error* A AENT B1 B2 BDISA BDISB BENT DOC ENT OV P1 P2 UFLAG VL O W) ;(setq bDis (getreal "\n Enter new value for Jump Radius: ")) ; Modified by David Prontnicki (setq bDisa bDisb) (setq bDisb (getreal (strcat "\n Enter new value for Jump Radius " (if (not bDisa) ": " (strcat "<" (itoa bDisa) ">: ") ) ) ) ) (if (and (not bDisb) bDisa) (setq bDisb bDisa) ) (defun *error* (msg) (and uFlag (vla-EndUndoMark doc)) (and ov (mapcar (function setvar) vl ov)) (and msg (or (wcmatch (strcase msg) "*BREAK,*CANCEL*,*EXIT*") (princ (strcat "\n** Error: " msg " **")))) (princ)) (setq doc (vla-get-ActiveDocument (vlax-get-acad-object)) vl '("PEDITACCEPT" "CMDECHO" "OSMODE") ov (mapcar (function getvar) vl)) (setvar "PEDITACCEPT" 1) (while (and (setq uFlag (not (vla-StartUndoMark doc))) (mapcar (function setvar) (cdr vl) '(0 32)) (setq p1 (getpoint "\nPick the crossing intersection: ")) ; Modified by David Prontnicki (setq ent (entsel "\nSelect the line to break: "))) ; Modified by David Prontnicki (setq p2 (osnap (cadr ent) "_nea") b1 (polar p1 (setq a (angle p1 p2)) bDisb) b2 (polar p1 (+ pi a) bDisb)) (setvar "OSMODE" 0) (command "_.break" b1 b2) (setq bEnt (entlast)) (if (> a (/ pi 2.)) (command "_.arc" b2 "_E" b1 "_A" 180.) (command "_.arc" b1 "_E" b2 "_A" 180.)) (setq aEnt (entlast)) (if (eq "LWPOLYLINE" (cdr (assoc 0 (entget (setq ent (car ent)))))) (progn (setq w (vla-get-ConstantWidth (setq o (vlax-ename->vla-object ent)))) (command "_.pedit" "_M" bEnt aEnt ent "" "_J" "" "") (vla-put-ConstantWidth (vlax-ename->vla-object (entlast)) w))) (setq uFlag (vla-EndUndoMark doc))) (*error* nil) (princ)) Thank you in advance! Quote
Lee Mac Posted November 3, 2015 Posted November 3, 2015 I have read the link you sent me (which is great by the way) and I am having a problem, not sure I fully understand. It always reads not the last value entered. You will see that I commented out my original change (setq bDis (getreal "\n Enter new value for Jump Radius: ")) which did work. The reason is because you have declared the symbol 'bDis' as a local variable, and hence the scope of this variable is limited to the c:jmpr function; consequently, every time the c:jmpr function is evaluated, a new value for the 'bDis' symbol is pushed onto the stack. Also note that the variable 'bDis' will become a double after the first valid input supplied to the getreal function, therefore, the itoa function will fail - this should be rtos. Quote
Lee Mac Posted November 3, 2015 Posted November 3, 2015 FWIW, here's another way to write it which may be clearer to understand, with the variable 'bDis' remaining local: (if (null myglobalvariable) (setq myglobalvariable 1.0) ) (if (setq bDis (getreal (strcat "\nJump Radius <" (rtos myglobalvariable) ">: "))) (setq myglobalvariable bDis) (setq bDis myglobalvariable) ) Quote
Cylis0509 Posted November 3, 2015 Author Posted November 3, 2015 FWIW, here's another way to write it which may be clearer to understand, with the variable 'bDis' remaining local: (if (null myglobalvariable) (setq myglobalvariable 1.0) ) (if (setq bDis (getreal (strcat "\nJump Radius <" (rtos myglobalvariable) ">: "))) (setq myglobalvariable bDis) (setq bDis myglobalvariable) ) Lee Mac, You are the man! Thank you and thank you for explaining the theory behind it as well. It means a lot and really helps me learn. It is greatly appreciated. Quote
satishrajdev Posted November 4, 2015 Posted November 4, 2015 So I tried appling your approach and it does not seem to be working for me, and I am 100% positive its because I'm not doing right. You will see that I have commented out my original piece of code requesting the radius and ATTEMPED your approach. I'm obviously not doing something right... I used GETINT so i put ITOA funtion to convert integer to string. From GETREAL you'll get real number and from converting it fo string you'll have to use RTOS. If you are keeping any input for future reference then you should not localising it as Lee sir mentioned. (/ *error* A AENT B1 B2 [color="red"]BDISA[/color] BDISB BENT DOC ENT OV P1 P2 UFLAG VL O W) Your code is updated here :- ;;; JMPR.lsp ;;; ;;; Description ;;; Jumper will auto-create the radius jump for pipe crossings. ;;; ;;; Author: Lee Mac (CADTutor) ;;; Date: 03/25/10 ;;; ;;; Revision: 1 ;;; Revision Date: 10/30/15 ;;; Description - Modified by David Prontnicki ;;; Added the ability to select your radius at the beginning of the command. ;;; Changed interface verbage ;;; ;;; Command: JMPR ;;; -----------------------------------------------------------------------------; (defun c:jmpr (/ *error* A AENT B1 B2 BDIS BENT DOC ENT OV P1 P2 UFLAG VL O W) ;(setq bDis (getreal "\n Enter new value for Jump Radius: ")) ; Modified by David Prontnicki (setq bDis (getreal (strcat "\n Enter new value for Jump Radius " (if (not (setq bDisa bDis)) ": " (strcat "<" (rtos bDisa) ">: ") ) ) ) ) (if (and (not bDis) bDisa) (setq bDis bDisa) ) (defun *error* (msg) (and uFlag (vla-EndUndoMark doc)) (and ov (mapcar (function setvar) vl ov)) (and msg (or (wcmatch (strcase msg) "*BREAK,*CANCEL*,*EXIT*") (princ (strcat "\n** Error: " msg " **")) ) ) (princ) ) (setq doc (vla-get-ActiveDocument (vlax-get-acad-object)) vl '("PEDITACCEPT" "CMDECHO" "OSMODE") ov (mapcar (function getvar) vl) ) (setvar "PEDITACCEPT" 1) (while (and (setq uFlag (not (vla-StartUndoMark doc))) (mapcar (function setvar) (cdr vl) '(0 32)) (setq p1 (getpoint "\nPick the crossing intersection: ")) ; Modified by David Prontnicki (setq ent (entsel "\nSelect the line to break: ")) ) ; Modified by David Prontnicki (setq p2 (osnap (cadr ent) "_nea") b1 (polar p1 (setq a (angle p1 p2)) bDis) b2 (polar p1 (+ pi a) bDis) ) (setvar "OSMODE" 0) (command "_.break" b1 b2) (setq bEnt (entlast)) (if (> a (/ pi 2.)) (command "_.arc" b2 "_E" b1 "_A" 180.) (command "_.arc" b1 "_E" b2 "_A" 180.) ) (setq aEnt (entlast)) (if (eq "LWPOLYLINE" (cdr (assoc 0 (entget (setq ent (car ent))))) ) (progn (setq w (vla-get-ConstantWidth (setq o (vlax-ename->vla-object ent)) ) ) (command "_.pedit" "_M" bEnt aEnt ent "" "_J" "" "") (vla-put-ConstantWidth (vlax-ename->vla-object (entlast)) w) ) ) (setq uFlag (vla-EndUndoMark doc)) ) (*error* nil) (princ) ) Quote
Lee Mac Posted November 4, 2015 Posted November 4, 2015 You are the man! Thank you and thank you for explaining the theory behind it as well. It means a lot and really helps me learn. It is greatly appreciated. You're most welcome Cylis0509, happy to help. 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.