flowerrobot Posted August 24, 2009 Share Posted August 24, 2009 Good Morning Ill say first Ive seach & search and i carnt find an answer. How do you dynamic print to the screen? I thought purhaps "grtext" would do it, But can not fine the suitable value, Only -2 & -1 seem to do any thing What im trying to achieve is while in a "Grread" mode, That each button is pressed to the screen.. That is easyer enought, if i dont want to remove it, However i can not accomidate for backspace in this manner. Hence im looking for an errase from command line option or a dynamic option. Well it kinda works, It wont remove thing, but overrides things Ive being testing with (while (setq hi (grread t 15 0)) (if (= (car hi) 2) (princ (chr (cadr hi))))) Any suggestions would be great. Cheers Flower Quote Link to comment Share on other sites More sharing options...
flowerrobot Posted August 24, 2009 Author Share Posted August 24, 2009 looks like i found bodged up way. Back space works in its a " ", or shows that it works So for every backspace, do a " ", then backspace again (while (setq hi (grread t 15 0)) (if (= (car hi) 2) (if (= (cadr hi) (progn (prompt (chr (cadr hi))) (prompt " ") (prompt (chr (cadr hi)))) (prompt (chr (cadr hi))) ) )) If any one knows a better way, please let me know, Thanks for you time Quote Link to comment Share on other sites More sharing options...
gile Posted August 25, 2009 Share Posted August 25, 2009 Hi, Here's the way I do it: (if (= (cadr gr) ;_ backspace (or (and str (/= str "") (setq str (substr str 1 (1- (strlen str)))) (princ (chr ) (princ (chr 32)) ) (setq str nil) ) (or (and str (setq str (strcat str (chr (cadr gr))))) (setq str (chr (cadr gr))) ) ) (and str (princ (chr (cadr gr)))) The entire routine which is no more than an example of grread using ;;; DSTAR (gile) 2009/03/09 ;;; Draws a star polygon ;;; The user specify the number of brunches, the star center and a point vertex location. (defun c:dstar (/ *error* makestar br imax ind cen loop gr star str pt) ;;;======================== LOCAL SUB ========================;;; ;; Local *error* (defun *error* (msg) (or (= msg "Function cancelled") (princ (strcat "Error: " msg)) ) (and star (entdel star) (setq star nil)) (grtext) (princ) ) ;; Creates the pline (defun makestar (cen ang dist br ind / n zdir lst1 lst2) (setq n (* 2 br) zdir (trans '(0 0 1) 1 0 T) ) (and (= (getvar "ORTHOMODE") 1) (setq ang (OrthoRound ang))) (repeat br (setq lst1 (cons (polar cen (+ ang (/ (* (setq n (- n 2)) pi) br)) dist) lst1 ) ) ) (repeat br (setq lst2 (cons (inters (nth n lst1) (nth (rem (+ n br (- ind)) br) lst1) (nth (rem (+ n (1- ind)) br) lst1) (nth (setq n (rem (+ n (1- br)) br)) lst1) ) lst2 ) ) ) (entmakex (append (list '(0 . "LWPOLYLINE") '(100 . "AcDbEntity") '(100 . "AcDbPolyline") (cons 90 (* 2 br)) '(70 . 1) (cons 38 (caddr (trans cen 1 zdir))) (cons 210 zdir) ) (mapcar (function (lambda (pt) (cons 10 (trans pt 1 zdir)) ) ) (apply 'append (apply 'mapcar (cons 'list (list lst1 lst2))) ) ) ) ) ) ;;;======================== MAIN ========================;;; (or *StarPointNumber* (setq *StarPointNumber* 5)) (if (setq br (getint (strcat "\nSpecify the number of points: <" (itoa *StarPointNumber*) ">: " ) ) ) (setq *StarPointNumber* br) (setq br *StarPointNumber*) ) (if (< 4 br) (progn (setq imax (fix (/ (- br 0.5) 2)) ind imax ) (initget 1) (setq cen (getpoint "\nSpecify the star center: ") loop T ) (princ "\nSpecify a point vertex (or enter circle radius): ") ;; grread loop (while (and (setq gr (grread T 12 0)) loop) (and star (entdel star) (setq star nil)) (cond ;; Dragging ((= 5 (car gr)) (setq ang (angle cen (cadr gr)) dist (distance cen (cadr gr)) ) (if (/= 0 dist) (setq star (makestar cen ang dist br ind)) ) (grtext -1 (strcat "Radius: " (rtos dist))) ) ;; Picked point = ends loop ((= 3 (car gr)) (makestar cen ang dist br ind) (setq loop nil) (grtext) ) ;; Right click = loops through available densities ((member (car gr) '(11 25)) (setq ind (+ 2 (rem (- (1+ ind) 2) (1- imax)))) ) ;; Enter = reads the command line input ((equal gr '(2 13)) (cond ;; valid distance = ends loop ((and str (setq dist (distof str)) (< 0 dist)) (makestar cen ang dist br ind) (setq loop nil) (grtext) ) ;; valid point = ends loop ((and str (setq pt (str->pt str))) (makestar cen (angle cen pt) (distance cen pt) br ind) (setq loop nil) (grtext) ) ;; invalid input (T (setq str nil) (princ "\nInvalid point or distance. Specify a point vertex (or enter circle radius): ") ) ) ) ;; F8 = toggles orthomode ((equal gr '(2 15)) (setvar "ORTHOMODE" (boole 6 1 (getvar "ORTHOMODE"))) (princ (chr ) (princ (chr 32)) ) ;; getting and printing command line input (T (if (= (cadr gr) ;_ backspace (or (and str (/= str "") (setq str (substr str 1 (1- (strlen str)))) (princ (chr ) (princ (chr 32)) ) (setq str nil) ) (or (and str (setq str (strcat str (chr (cadr gr))))) (setq str (chr (cadr gr))) ) ) (and str (princ (chr (cadr gr)))) ) ) ) ) (prompt "\nThe number of points have to be greater than 4.") ) (princ) ) ;;;======================== SUB ROUTINES ========================;;; ;; OrthoRound ;; Returns the angle rounded to pi/2 ;; ;; Argument: an angle (radians) (defun OrthoRound (ang) (* (/ pi 2) (fix (/ (+ (/ pi 4) ang) (/ pi 2)))) ) ;; STR2PT ;; Convert a string into a 3d point (input with grread) ;; ;; Argument: a string (ex: "25,63") ;; Return: a 3d point (ex (25.0 63.0 0.0) or nil if invalid string (defun str2pt (str) (setq str (mapcar 'read (str2lst str ","))) (if (and (vl-every 'numberp str) (< 1 (length str) 4) ) (trans str 0 0) ) ) ;; STR2LST ;; Transforms a string with separator into a list of strings ;; ;; Arguments ;; str = the string ;; sep = the separator pattern (defun str2lst (str sep / pos) (if (setq pos (vl-string-search sep str)) (cons (substr str 1 pos) (str2lst (substr str (+ (strlen sep) pos 1)) sep) ) (list str) ) Quote Link to comment Share on other sites More sharing options...
Lee Mac Posted August 25, 2009 Share Posted August 25, 2009 Check this from CAB: (defun c:test(/ user ent) (setq user (getpoint_or_text 2 "\nSelect or enter name. ")) (cond ((null user) (prompt "\nUser Quit.")) ((= (type user) 'STR) (prompt (strcase "\nUser entered " user))) ((listp user) (if (setq ent (nentselp user)) (prompt "\nObject selected.") (prompt "\nNothing selected.") ) ) (t (prompt "\nInvalid selection.")) ) (princ) ) ;; http://www.theswamp.org/index.php?topic=11342.msg143630#msg143630 ;;;=======================[ getpoint_or_text.lsp ]======================= ;;; Author: Copyright© 2005 Charles Alan Butler ;;; Version: 1.0 Dec. 12, 2005 ;;; Purpose: To get user entered text or picked point ;;; Sub_Routines: -None ;;; Requirements: -ctype is the cursor type ;;; 0 Display the normal crosshairs. ;;; 1 Do not display a cursor (no crosshairs). ;;; 2 Display the object-selection "target" cursor ;;; -prmpt is the user prompt, start it with \n ;;; Returns: - picked point or ;;; the user entered text or ;;; "" for Enter Key ;;; nil for Escape Key ;;;============================================================== (defun getpoint_or_text (ctype prmpt / char code data result flag p str) (vl-load-com) (vl-catch-all-apply '(lambda () (setq flag t str "" ) (princ prmpt) (while flag (setq p (grread t 15 ctype) code (car p) data (cadr p) ) (cond ((= code 3) ; clicked point (setq result data flag nil ) ) ((= code 2) ; keyboard (setq char data) (cond ((<= 32 char 126) (princ (chr char)) (setq str (strcat str (chr char))) ) ((= char ;; backspace was hit .. go chop off a character (and (> (strlen str) 0) (princ (strcat (chr " " (chr )) (setq str (substr str 1 (1- (strlen str)))) ) ) ((= char 13) (setq result str flag nil ) ) ) ) ) ) ;_ while ) ) result ) Quote Link to comment Share on other sites More sharing options...
flowerrobot Posted August 25, 2009 Author Share Posted August 25, 2009 Thanks for that guys, I ended up doing it another way, yet very simmalr to thoese. Will look a bit closer at thoese codes you have posted up, Thanks heaps For reference this is the way i did it (cond .... ((= (car reader) 2) (cond ((= (cadr reader) (if (> TxtCount 0) (progn (setq TxtCount (1- TxtCount) TextList (cdr TextList)) (prompt (chr ) (prompt (chr 32)) (prompt (chr ) ))) ((or (= (cadr reader) 32)(= (cadr reader) 13)) (setq ShortSnap (strcase (vl-list->string (reverse TextList))) Quote Link to comment Share on other sites More sharing options...
Freerefill Posted August 26, 2009 Share Posted August 26, 2009 This came about from my attempt to put a LISP shell over the AutoCAD command line... which failed, and then became me playing around with cheesy video games... (defun gr_main(op input / ); (cond ((= op 0) (vl-load-com) (setvar "cmdecho" 0) (setq #p_mai "Prompt: " #m_run T #d_ist "" #d_sta T #m_csr 0) (setq #d_lst nil #d_mps nil #p_ntf nil #p_dum nil #p_ret nil #d_pre nil #o_lnm "GR_ARCADE") ) ((= op 1) (if #d_sta (cond ((= (cadr input) (if (> (strlen #d_ist) 0) (princ (strcat "\010" " " "\010"))) (setq #d_ist (substr #d_ist 1 (1- (strlen #d_ist))))) ((or (= (cadr input) 13) (= (cadr input) 32)) (repeat (+ (strlen #d_ist) (strlen #p_cur)) (princ (strcat "\010" " " "\010"))) (princ #p_cur) (setq #d_pre input) (setq #d_lst (append #d_lst (list #d_ist)) #d_ist "")) ((= (car input) 2) (setq #d_ist (strcat #d_ist (chr (cadr input))) #d_pre input) (princ (chr (cadr input)))) ((and (= (car input) 3) (= #d_ist "")) (setq #d_pre (cadr input)) (setq #d_lst (append #d_lst (list (cadr input))))) ((= (car input) 5) (setq #d_mps (cadr input))) ) (cond ((= (car input) 2) (setq #d_lst (append #d_lst (list (chr (cadr input))))) (setq #d_pre input)) ((= (car input) 3) (setq #d_lst (append #d_lst (list (cadr input)))) ) ((= (car input) 5) (setq #d_mps (cadr input))) ) ) ) ((= op 4) (setq #d_pre nil) ) ) (princ) ) It's got a lot of unnecessary stuff, mainly because this is a "hacked apart" version of Pong, stripped down to the prompt control. It works, though. Just my two cents. ^^ Quote Link to comment Share on other sites More sharing options...
Lee Mac Posted August 26, 2009 Share Posted August 26, 2009 This came about from my attempt to put a LISP shell over the AutoCAD command line... which failed... *resists urge to say 'I told you so...' * Quote Link to comment Share on other sites More sharing options...
flowerrobot Posted August 27, 2009 Author Share Posted August 27, 2009 Must admit, that was increadbly hard to follow, Soon as you add a # in, my little brain exploded. Havnt worked out yet, How/what is doing. But no dought you understand the application of this that im using it in, and if you can recommend a better/simpler way, Please Let me know. Thanks! Flower Quote Link to comment Share on other sites More sharing options...
Freerefill Posted August 28, 2009 Share Posted August 28, 2009 The # notation means nothing. It's just a variable. The variables you see there are actually used and modified outside of the "main" function, meaning they were global for the entire program. For that, since the overall program was going to be quite vast (for my level, at least), I wanted to keep track of all of my variables. The #d_ means it's a data variable, the #p_ means a prompt, et cetera. It's just like using, say, "str1" and "str2" as your variables. You're indicating that it's a string, and it's different from other strings. That's really it. The only thing I did different is wrap that all up in a tidy interface, and set it so that when you hit 'enter' or 'spacebar' it takes the finished product, sets it equal to a variable, and sends it off. Well, sort of. You see a #d_lst in my code. That's my data list; it keeps track of all the input in order that it was inputted. There's a reason for that, trust me.. Also, I apologize for being way too tired yesterday. I seem to have not posted all of my code. Here it is with the loop that actually uses the condition I posted. (defun c:test( / #p_mai #d_err #d_lst #d_mps #d_pre #d_grd #m_csr #m_run); (load "Y:\\Mercier Mark\\LISP\\#recstats.lsp" "nil")(#recstats "NOMNOM") (gr_main 0 nil) ; Setup program space (princ (strcat "\n" (setq #p_cur #p_mai))) ; Display prompt (while (and #m_run ; Begin main loop (setq #d_err (vl-catch-all-apply '(lambda ( ) (setq #d_grd (grread nil 13 #m_csr))))) (not (vl-catch-all-error-p #d_err))) (gr_main 1 #d_grd) ; Capture data ); End main While loop (princ "\nGoodbye.")(princ) ) (defun gr_main(op input / ); (cond ((= op 0) (vl-load-com) (setvar "cmdecho" 0) (setq #p_mai "Command :3 " #m_run T #d_ist "" #d_sta T #m_csr 0 #d_lst nil #d_mps nil #d_pre nil) ((= op 1) (if #d_sta (cond ((= (cadr input) (if (> (strlen #d_ist) 0) (princ (strcat "\010" " " "\010"))) (setq #d_ist (substr #d_ist 1 (1- (strlen #d_ist))))) ((or (= (cadr input) 13) (= (cadr input) 32)) (repeat (+ (strlen #d_ist) (strlen #p_cur)) (princ (strcat "\010" " " "\010"))) (princ #p_cur) (setq #d_pre #d_ist) (setq #d_lst (append #d_lst (list #d_ist)) #d_ist "")) ((= (car input) 2) (setq #d_ist (strcat #d_ist (chr (cadr input)))) (princ (chr (cadr input)))) ((and (= (car input) 3) (= #d_ist "")) (setq #d_pre (cadr input)) (setq #d_lst (append #d_lst (list (cadr input))))) ((= (car input) 5) (setq #d_mps (cadr input))) ) (cond ((= (car input) 2) (setq #d_lst (append #d_lst (list (chr (cadr input))))) (setq #d_pre (chr (cadr input)))) ((= (car input) 3) (setq #d_lst (append #d_lst (list (cadr input)))) ;(setq #d_pre (cadr input)) ) ((= (car input) 5) (setq #d_mps (cadr input))) ) ) ) ) (princ) ) That's got the loop in there as well. Quote Link to comment Share on other sites More sharing options...
alanjt Posted August 28, 2009 Share Posted August 28, 2009 guess i'm not the only one that likes to preface variables with a # The # notation means nothing. It's just a variable. The variables you see there are actually used and modified outside of the "main" function, meaning they were global for the entire program. For that, since the overall program was going to be quite vast (for my level, at least), I wanted to keep track of all of my variables. The #d_ means it's a data variable, the #p_ means a prompt, et cetera. It's just like using, say, "str1" and "str2" as your variables. You're indicating that it's a string, and it's different from other strings. That's really it. The only thing I did different is wrap that all up in a tidy interface, and set it so that when you hit 'enter' or 'spacebar' it takes the finished product, sets it equal to a variable, and sends it off. Well, sort of. You see a #d_lst in my code. That's my data list; it keeps track of all the input in order that it was inputted. There's a reason for that, trust me.. Also, I apologize for being way too tired yesterday. I seem to have not posted all of my code. Here it is with the loop that actually uses the condition I posted. (defun c:test( / #p_mai #d_err #d_lst #d_mps #d_pre #d_grd #m_csr #m_run); (load "Y:\\Mercier Mark\\LISP\\#recstats.lsp" "nil")(#recstats "NOMNOM") (gr_main 0 nil) ; Setup program space (princ (strcat "\n" (setq #p_cur #p_mai))) ; Display prompt (while (and #m_run ; Begin main loop (setq #d_err (vl-catch-all-apply '(lambda ( ) (setq #d_grd (grread nil 13 #m_csr))))) (not (vl-catch-all-error-p #d_err))) (gr_main 1 #d_grd) ; Capture data ); End main While loop (princ "\nGoodbye.")(princ) ) (defun gr_main(op input / ); (cond ((= op 0) (vl-load-com) (setvar "cmdecho" 0) (setq #p_mai "Command :3 " #m_run T #d_ist "" #d_sta T #m_csr 0 #d_lst nil #d_mps nil #d_pre nil) ((= op 1) (if #d_sta (cond ((= (cadr input) (if (> (strlen #d_ist) 0) (princ (strcat "\010" " " "\010"))) (setq #d_ist (substr #d_ist 1 (1- (strlen #d_ist))))) ((or (= (cadr input) 13) (= (cadr input) 32)) (repeat (+ (strlen #d_ist) (strlen #p_cur)) (princ (strcat "\010" " " "\010"))) (princ #p_cur) (setq #d_pre #d_ist) (setq #d_lst (append #d_lst (list #d_ist)) #d_ist "")) ((= (car input) 2) (setq #d_ist (strcat #d_ist (chr (cadr input)))) (princ (chr (cadr input)))) ((and (= (car input) 3) (= #d_ist "")) (setq #d_pre (cadr input)) (setq #d_lst (append #d_lst (list (cadr input))))) ((= (car input) 5) (setq #d_mps (cadr input))) ) (cond ((= (car input) 2) (setq #d_lst (append #d_lst (list (chr (cadr input))))) (setq #d_pre (chr (cadr input)))) ((= (car input) 3) (setq #d_lst (append #d_lst (list (cadr input)))) ;(setq #d_pre (cadr input)) ) ((= (car input) 5) (setq #d_mps (cadr input))) ) ) ) ) (princ) ) That's got the loop in there as well. Quote Link to comment Share on other sites More sharing options...
flowerrobot Posted August 30, 2009 Author Share Posted August 30, 2009 Also, I apologize for being way too tired yesterday. I seem to have not posted all of my code. Here it is with the loop that actually uses the condition I posted. LoL, makes much more sence, thanks! # only confuses me because im not used to seeing it But i think it may be of good pratice to use #,Particualy in large programs, would also helps keep track values, (aka a lisp that reads a file, and adds all #... to a list), Because how i do things now, Can leave me missing varible's some times. Regards Flower Quote Link to comment Share on other sites More sharing options...
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.