shadi Posted December 11, 2021 Posted December 11, 2021 hello everyone , hope u all doing so great ... my problem here that i want easy way to insert numbers in autocad without trying to make texts or adjust them .. i wanna lisp make the number i press from keyboard be inserted into text or mtext and i just click the location of that text in cad ... hope somebody could help me in this ... thanks in advance Quote
mhupp Posted December 11, 2021 Posted December 11, 2021 (edited) Your wanting to add text on to existing text or all new text? You could modify one of my lisp if you need to add a number at the end. ;;----------------------------------------------------------------------------;; ;; ADD TEXT PREFIX OR SUFFIX TO EXISTING TEXT (defun C:TXT (/ rep str *str ss txt sn ent e) (initget "Prefix Suffix") (setq rep (cond ((getkword "\nAdd Text to [Prefix/Suffix]<Suffix>:")) ("Suffix") ;defaults to suffix ) ) (or (setq *str (getenv "Insert-Text")) (setq *str "Here")) ;gets last string from registry (if (= "" (setq str (getstring (strcat "\nEnter " rep " Text \"" *str "\": ")))) (setq str *str) ) (setenv "Insert-Text" str) ;saves to registry (if (setq ss (ssget "_:L" '((0 . "*TEXT")))) (foreach ent (vl-remove-if 'listp (mapcar 'cadr (ssnamex SS))) (setq txt (vlax-ename->vla-object ent)) (cond ((= rep "Prefix") (vla-put-textstring txt (strcat str (vla-get-textstring txt))) ) ((= rep "Suffix") (vla-put-textstring txt (strcat (vla-get-textstring txt) str)) ) ) ) ) (princ) ) Also check this out for numbering things Edited December 12, 2021 by mhupp 1 Quote
shadi Posted December 12, 2021 Author Posted December 12, 2021 20 hours ago, mhupp said: Your wanting to add text on to existing text or all new text? You could modify one of my lisp if you need to add a number at the end. ;;----------------------------------------------------------------------------;; ;; ADD TEXT PREFIX OR SUFFIX TO EXISTING TEXT (defun C:TXT (/ rep str *str ss txt sn ent e) (initget "Prefix Suffix") (setq rep (cond ((getkword "\nAdd Text to [Prefix/Suffix]<Suffix>:")) ("Suffix") ;defaults to suffix ) ) (or (setq *str (getenv "Insert-Text")) (setq *str "Here")) ;gets last string from registry (if (= "" (setq str (getstring (strcat "\nEnter " rep " Text \"" *str "\": ")))) (setq str *str) ) (setenv "Insert-Text" str) ;saves to registry (if (setq ss (ssget "_:L" '((0 . "*TEXT")))) (foreach ent (vl-remove-if 'listp (mapcar 'cadr (ssnamex SS))) (setq txt (vlax-ename->vla-object ent)) (cond ((= rep "Prefix") (vla-put-textstring txt (strcat str (vla-get-textstring txt))) ) ((= rep "Suffix") (vla-put-textstring txt (strcat (vla-get-textstring txt) str)) ) ) ) ) (princ) ) Also check this out for numbering things thank u mhupp for ur answer .. i meant new texts or mtexts to be fast way of inserting numbers , as an example i press 1 so text creating with 1 inside it after pressing space to end that , press 6 then 5 so another text with 6 number inside it creating after space pressed ... u got it ? Quote
mhupp Posted December 12, 2021 Posted December 12, 2021 This will ask the user for text and a point then create mtext at that location. will loop until new text isn't created (defun C:foo (/ LastEntity ThisEntity txt pt) (setq LastEntity t) (while (not (equal LastEntity ThisEntity)) (setq txt (getstring t "\nEnter Text: ")) (if (/= txt "") (setq pt (getpoint "Select Insertion Point")) (setq txt nil) ) (setq LastEntity (entlast)) (if (and txt pt) (entmake (list '(0 . "MTEXT") '(71 . 5) '(100 . "AcDbEntity") '(100 . "AcDbMText") (cons 1 txt) (cons 10 pt) ;Insertion Point (cons 40 (getvar "TextSize")) ) ) ) (setq ThisEntity (entlast)) ) (princ) ) 1 1 Quote
shadi Posted December 12, 2021 Author Posted December 12, 2021 2 hours ago, mhupp said: This will ask the user for text and a point then create mtext at that location. will loop until new text isn't created (defun C:foo (/ LastEntity ThisEntity txt pt) (setq LastEntity t) (while (not (equal LastEntity ThisEntity)) (setq txt (getstring t "\nEnter Text: ")) (if (/= txt "") (setq pt (getpoint "Select Insertion Point")) (setq txt nil) ) (setq LastEntity (entlast)) (if (and txt pt) (entmake (list '(0 . "MTEXT") '(71 . 5) '(100 . "AcDbEntity") '(100 . "AcDbMText") (cons 1 txt) (cons 10 pt) ;Insertion Point (cons 40 (getvar "TextSize")) ) ) ) (setq ThisEntity (entlast)) ) (princ) ) very nice , this is so cool , i tried it , it working well , thanks much ... just if u can remove pressing enter button after writing every time , as for example . i press 1 then 2 and locate the point of insertion 12 text without pressing enter Quote
mhupp Posted December 12, 2021 Posted December 12, 2021 (edited) Doesn't work like that. You know what you want to input but how does the computer know when your done inputting and to move on to the next step? I guess a timer could be set . How long do you make it to time out? make it to fast and you might not input anything and have to repeat the command. make it to long and its not saving anytime. what happens if you input the wrong thing and try and change it to late times up moving on. Whats the big deal with hitting enter? You can also right click with your mouse if setup properly. Only other thing i can think of is to remove the t in getstring. This means you can't use spaces anymore so when you hit the space bar it acts like enter. (setq txt (getstring t "\nEnter Text: ")) to (setq txt (getstring "\nEnter Text: ")) Edited December 12, 2021 by mhupp 1 Quote
shadi Posted December 12, 2021 Author Posted December 12, 2021 7 minutes ago, mhupp said: Doesn't work like that. You know what you want to input but how does the computer know when your done inputting and to move on to the next step? I guess a timer could be set . How long do you make it to time out? make it to fast and you might not input anything and have to repeat the command. make it to long and its not saving anytime. what happens if you input the wrong thing and try and change it to late times up moving on. Whats the big deal with hitting enter? You can also right click with your mouse if setup properly. Only other thing i can think of is to remove the t in getstring. This means you can use spaces anymore so when you hit the space bar it like enter. (setq txt (getstring t "\nEnter Text: ")) to (setq txt (getstring "\nEnter Text: ")) i am sorry , i thought there is a way to do texts without enter , i appreciate ur work ... thank u a lot for ur help 1 Quote
mhupp Posted December 12, 2021 Posted December 12, 2021 (edited) 3 minutes ago, shadi said: i am sorry , i thought there is a way to do texts without enter , i appreciate ur work ... thank u a lot for ur help Maybe, I don't know everything. if your going in sequential order you might have missed what i posted before. http://www.lee-mac.com/numinc.html Edited December 12, 2021 by mhupp Quote
BIGAL Posted December 12, 2021 Posted December 12, 2021 It may be possible with .net where you look at the keyboard buffer not Acad. Way above my pay rate. A quick google suggest yes. Keyboard Events Keyboard events are generated when any key is pressed or released 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.