mixxer Posted December 29, 2012 Share Posted December 29, 2012 Ok guys, thanks for being here for us. I 'm a beginner in lisp and this is my first post. I'm trying to write a lisp which is going to create a txt-numeric description of a point (+1 number for every next point) and to put it on a point which is defined by user. In a moment when lisp creates a text for a point, I would like it to be visible and docked to a cursor until I click on a place where it will be positioned. Can you suggest me how to write that down in a lisp? Thank you in advance. This is my lisp: (defun c:descr (/ startNum inp rot) (setq startNum (getint "\nInsert start number <1>: ")) (if (= startNum nil)(setq startNum 1)) (setq rot (getreal "\nInser txt rotation angle <0>: ")) (if (= rot nil)(setq rot 0)) (setq inp (getpoint "Specify first point: ")) (while inp (command "text" inp 1.5 rot startNum) (setq inp (getpoint "Specify next point: ")) (setq startNum (+ startNum 1)) ) (princ) ) Quote Link to comment Share on other sites More sharing options...
Lee Mac Posted December 29, 2012 Share Posted December 29, 2012 Maybe this will help you: Incremental Numbering Suite Quote Link to comment Share on other sites More sharing options...
mixxer Posted December 29, 2012 Author Share Posted December 29, 2012 Thanks Lee Mac, that is something what I need, but I'm trying to learn lisp and this routine is too complicated and I cannot find this part related with text follow cursor issue Quote Link to comment Share on other sites More sharing options...
pBe Posted December 30, 2012 Share Posted December 30, 2012 if you need a simple code (defun c:descr (/ startNum inp rot) [color="blue"](defun chg () (setq ent (entget (entlast))) (entmod (subst (cons 1 (itoa (setq startNum (1+ startNum)))) (assoc 1 ent) ent )))[/color] (setq startNum (getint "\nInsert start number <1>: ")) (if (= startNum nil) (setq startNum 1) ) (setq rot (getreal "\nInser txt rotation angle <0>: ")) (if (= rot nil) (setq rot 0) ) (setq inp (getpoint "Specify first point: ")) (command "text" inp 1.5 rot startNum) [color="blue"](while (and (princ "\nPress Escape to terminate:") (not (command "_copy" (entlast) "" inp pause (chg))) (setq inp (getvar 'lastpoint)) ))[/color] (princ) ) Remember to press ESC to terminate command. The snippet above can be modified to account if any key other than ESC pressed by the USER to terminate the program. HTH Quote Link to comment Share on other sites More sharing options...
mixxer Posted December 31, 2012 Author Share Posted December 31, 2012 Thanks pBe that is what I need, but since I'm a beginner can you explain me what happens in "while" tag. I somehow managed to understand "defun chg" function. Thanks again Quote Link to comment Share on other sites More sharing options...
pBe Posted December 31, 2012 Share Posted December 31, 2012 Thanks pBe that is what I need, but since I'm a beginner can you explain me what happens in "while" tag. In the case above, the only way to terminate while expression is to press ESC and not a clean exit by any means and not really the ideal way of using a while . I was thinking of using grread function to terminate the loop by any pressing any key, The usage of said function for certain will open a can of worms for beginners. Better take it slow mixxer. The while function in general will evaluate an expression and stays in a "loop" as long as the condition is not nil example: (while (setq object (Car (entsel "\nSelect Object: "))) ;<---- this line is the condition, will prompt you as long you keep selecting an entity (princ (strcat "\nSelected object is a " (cdr (assoc 0 (entget object))) ) ;_ end of strcat ) ;_ end of princ ) ;_ end of while Cheers Quote Link to comment Share on other sites More sharing options...
David Bethel Posted December 31, 2012 Share Posted December 31, 2012 Welcome aboard, This uses (entmake) to create the TEXT. It gives you more control over the text options and display values: Same basic engine though: [b][color=BLACK]([/color][/b]defun c:descr [b][color=FUCHSIA]([/color][/b]/ sdef num rot inp[b][color=FUCHSIA])[/color][/b] [b][color=FUCHSIA]([/color][/b]setq sdef [b][color=NAVY]([/color][/b]if global_sdef global_sdef 1[b][color=NAVY])[/color][/b][b][color=FUCHSIA])[/color][/b] [b][color=FUCHSIA]([/color][/b]initget 0[b][color=FUCHSIA])[/color][/b] [b][color=FUCHSIA]([/color][/b]setq num [b][color=NAVY]([/color][/b]getint [b][color=MAROON]([/color][/b]strcat [color=#2f4f4f]"\nStarting Number <"[/color] [b][color=GREEN]([/color][/b]itoa sdef[b][color=GREEN])[/color][/b][color=#2f4f4f]">: "[/color][b][color=MAROON])[/color][/b][b][color=NAVY])[/color][/b][b][color=FUCHSIA])[/color][/b] [b][color=FUCHSIA]([/color][/b]or num [b][color=NAVY]([/color][/b]setq num sdef[b][color=NAVY])[/color][/b][b][color=FUCHSIA])[/color][/b] [b][color=FUCHSIA]([/color][/b]setq global_sdef num[b][color=FUCHSIA])[/color][/b] [b][color=FUCHSIA]([/color][/b]initget 0[b][color=FUCHSIA])[/color][/b] [b][color=FUCHSIA]([/color][/b]setq rot [b][color=NAVY]([/color][/b]getangle [color=#2f4f4f]"\nInsert Text Rotation Angle <0>: "[/color][b][color=NAVY])[/color][/b][b][color=FUCHSIA])[/color][/b] [b][color=FUCHSIA]([/color][/b]or rot [b][color=NAVY]([/color][/b]setq rot 0[b][color=NAVY])[/color][/b][b][color=FUCHSIA])[/color][/b] [b][color=FUCHSIA]([/color][/b]while [b][color=NAVY]([/color][/b]setq inp [b][color=MAROON]([/color][/b]getpoint [b][color=GREEN]([/color][/b]strcat [color=#2f4f4f]"\nPoint Number "[/color] [b][color=BLUE]([/color][/b]itoa num[b][color=BLUE])[/color][/b] [color=#2f4f4f]" Location: "[/color][b][color=GREEN])[/color][/b][b][color=MAROON])[/color][/b][b][color=NAVY])[/color][/b] [color=#8b4513];;;MAIN TEXT ENTITY VALUES[/color] [b][color=NAVY]([/color][/b]entmake [b][color=MAROON]([/color][/b]list [b][color=GREEN]([/color][/b]cons 0 [color=#2f4f4f]"TEXT"[/color][b][color=GREEN])[/color][/b] [b][color=GREEN]([/color][/b]cons 1 [b][color=BLUE]([/color][/b]itoa num[b][color=BLUE])[/color][/b][b][color=GREEN])[/color][/b] [b][color=GREEN]([/color][/b]cons 10 inp[b][color=GREEN])[/color][/b] [b][color=GREEN]([/color][/b]cons 50 rot[b][color=GREEN])[/color][/b] [b][color=GREEN]([/color][/b]cons 40 1.5[b][color=GREEN])[/color][/b] [color=#8b4513];;;TEXT SCALE AND OBLIQUE ANGLE[/color] [b][color=GREEN]([/color][/b]assoc 41 [b][color=BLUE]([/color][/b]tblsearch [color=#2f4f4f]"STYLE"[/color] [b][color=RED]([/color][/b]getvar [color=#2f4f4f]"TEXTSTYLE"[/color][b][color=RED])[/color][/b][b][color=BLUE])[/color][/b][b][color=GREEN])[/color][/b] [b][color=GREEN]([/color][/b]cons 51 [b][color=BLUE]([/color][/b]cdr [b][color=RED]([/color][/b]assoc 50 [b][color=PURPLE]([/color][/b]tblsearch [color=#2f4f4f]"STYLE"[/color] [b][color=TEAL]([/color][/b]getvar [color=#2f4f4f]"TEXTSTYLE"[/color][b][color=TEAL])[/color][/b][b][color=PURPLE])[/color][/b][b][color=RED])[/color][/b][b][color=BLUE])[/color][/b][b][color=GREEN])[/color][/b] [color=#8b4513];;;TEXT JUSTIFICATIONS[/color] [b][color=GREEN]([/color][/b]cons 11 [b][color=BLUE]([/color][/b]list 0 0 0[b][color=BLUE])[/color][/b][b][color=GREEN])[/color][/b] [b][color=GREEN]([/color][/b]cons 71 0[b][color=GREEN])[/color][/b] [b][color=GREEN]([/color][/b]cons 72 0[b][color=GREEN])[/color][/b] [b][color=GREEN]([/color][/b]cons 73 0[b][color=GREEN])[/color][/b] [color=#8b4513];;;CURRENT ENTITY CONSTURUCTION SETTINGS[/color] [b][color=GREEN]([/color][/b]cons 7 [b][color=BLUE]([/color][/b]getvar [color=#2f4f4f]"TEXTSTYLE"[/color][b][color=BLUE])[/color][/b][b][color=GREEN])[/color][/b] [b][color=GREEN]([/color][/b]cons 8 [b][color=BLUE]([/color][/b]getvar [color=#2f4f4f]"CLAYER"[/color][b][color=BLUE])[/color][/b][b][color=GREEN])[/color][/b] [b][color=GREEN]([/color][/b]cons 6 [b][color=BLUE]([/color][/b]getvar [color=#2f4f4f]"CELTYPE"[/color][b][color=BLUE])[/color][/b][b][color=GREEN])[/color][/b] [b][color=GREEN]([/color][/b]cons 39 [b][color=BLUE]([/color][/b]getvar [color=#2f4f4f]"THICKNESS"[/color][b][color=BLUE])[/color][/b][b][color=GREEN])[/color][/b] [b][color=GREEN]([/color][/b]cons 62 [b][color=BLUE]([/color][/b]cond [b][color=RED]([/color][/b][b][color=PURPLE]([/color][/b]= [b][color=TEAL]([/color][/b]getvar [color=#2f4f4f]"CECOLOR"[/color][b][color=TEAL])[/color][/b] [color=#2f4f4f]"BYLAYER"[/color][b][color=PURPLE])[/color][/b] 256[b][color=RED])[/color][/b] [b][color=RED]([/color][/b][b][color=PURPLE]([/color][/b]= [b][color=TEAL]([/color][/b]getvar [color=#2f4f4f]"CECOLOR"[/color][b][color=TEAL])[/color][/b] [color=#2f4f4f]"BYBLOCK"[/color][b][color=PURPLE])[/color][/b] 0[b][color=RED])[/color][/b] [b][color=RED]([/color][/b]T [b][color=PURPLE]([/color][/b]atoi [b][color=TEAL]([/color][/b]getvar [color=#2f4f4f]"CECOLOR"[/color][b][color=TEAL])[/color][/b][b][color=PURPLE])[/color][/b][b][color=RED])[/color][/b][b][color=BLUE])[/color][/b][b][color=GREEN])[/color][/b] [b][color=GREEN]([/color][/b]cons 210 [b][color=BLUE]([/color][/b]trans '[b][color=RED]([/color][/b]0 0 1[b][color=RED])[/color][/b] 0 1[b][color=BLUE])[/color][/b][b][color=GREEN])[/color][/b][b][color=MAROON])[/color][/b][b][color=NAVY])[/color][/b] [b][color=NAVY]([/color][/b]setq num [b][color=MAROON]([/color][/b]1+ num[b][color=MAROON])[/color][/b][b][color=NAVY])[/color][/b][b][color=FUCHSIA])[/color][/b] [b][color=FUCHSIA]([/color][/b]prin1[b][color=FUCHSIA])[/color][/b][b][color=BLACK])[/color][/b] Have fun! -David Quote Link to comment Share on other sites More sharing options...
pBe Posted December 31, 2012 Share Posted December 31, 2012 FWIW: Additional code utilizing grread (defun c:descr (/ sdef num rot inp inp2 ent end NewObj) (vl-load-com) (setq sdef (if global_sdef global_sdef 1)) (initget 0) (setq num (getint (strcat "\nStarting Number <" (itoa sdef)">: "))) (or num (setq num sdef)) (setq global_sdef num) (initget 0) (setq rot (getangle "\nInsert Text Rotation Angle <0>: ")) (or rot (setq rot 0)) (if (setq inp (getpoint (strcat "\nPoint Number " (itoa num) " Location: "))) (progn (entmake (list (cons 0 "TEXT") (cons 1 (itoa num)) (cons 10 inp) (cons 50 rot) (cons 40 1.5) ;;;TEXT SCALE AND OBLIQUE ANGLE (assoc 41 (tblsearch "STYLE" (getvar "TEXTSTYLE"))) (cons 51 (cdr (assoc 50 (tblsearch "STYLE" (getvar "TEXTSTYLE"))))) ;;;TEXT JUSTIFICATIONS (cons 11 (list 0 0 0)) (cons 71 0) (cons 72 0) (cons 73 0) ;;;CURRENT ENTITY CONSTURUCTION SETTINGS (cons 7 (getvar "TEXTSTYLE")) (cons 8 (getvar "CLAYER")) (cons 6 (getvar "CELTYPE")) (cons 39 (getvar "THICKNESS")) (cons 62 (cond ((= (getvar "CECOLOR") "BYLAYER") 256) ((= (getvar "CECOLOR") "BYBLOCK") 0) (T (atoi (getvar "CECOLOR"))))) (cons 210 (trans '(0 0 1) 0 1)))) [color="blue"](setq ent (vlax-ename->vla-object (entlast))) (setq end nil inp (vlax-get ent 'insertionpoint)) (setq NewObj (vla-copy ent)) (while (null end) (while (progn (prompt "\rPick Next Point/ Any key to Exit") (setq gr (grread t 15 0) code (car gr) data (cadr gr) ) (cond ((= 5 code) (vlax-invoke NewObj 'Move inp (setq inp2 data)) (setq inp inp2)) ((= 2 code)(setq end T)(entdel (entlast)) nil) ((= 3 code) (vlax-invoke NewObj 'Move inp (setq inp2 data)) (vla-put-textstring NewObj (itoa (setq num (1+ num)))) (setq ent NewObj) (setq NewObj (vla-copy ent)) nil) ) ) ) )[/color] ) ) (princ) ) Its a bit messy though. Have fun dissecting the grread line of the code Learn about grread here: http://www.cadtutor.net/forum/showthread.php?57304-Get-quot-alert-quot-when-pressing-a-key-in-a-while-loop-how&highlight=Wrap+statements+expression Happy New Year to all. Quote Link to comment Share on other sites More sharing options...
mixxer Posted January 2, 2013 Author Share Posted January 2, 2013 (edited) Happy New Year And thanks for your answers guys @ pBe I understand that part but all next lines are what I don't understand [color=blue](not (command "_copy" (entlast) "" inp pause (chg))) (setq inp (getvar 'lastpoint)) )[/color] And for grread function I need more time. I will bother you guys with more questions if you don't mind Edited January 2, 2013 by mixxer 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.