Sweety Posted August 24, 2010 Share Posted August 24, 2010 Hi, I have a problem with the strcat , and it is not goining values . (setq num 1) (while (setq pt (getpoint "\n Enter Coordinates points :")) (setq num (1+ num)) (setq txt (strcat "W" num)) (entmakex (list '(0 . "TEXT") (cons 40 (getvar 'textsize)) (cons 1 txt) (cons 10 pt) ) ) ) Any help? Thanks Quote Link to comment Share on other sites More sharing options...
lpseifert Posted August 24, 2010 Share Posted August 24, 2010 the variable num is an integer not a string. Use rtos to convert it to a string first (strcat "W" (rtos num 2 0)) Quote Link to comment Share on other sites More sharing options...
Sweety Posted August 24, 2010 Author Share Posted August 24, 2010 Wonderful . Thank you soooooooooo much. Sweety. Quote Link to comment Share on other sites More sharing options...
BlackBox Posted August 24, 2010 Share Posted August 24, 2010 My two cents... the variable num is an integer not a string. Use rtos to convert it to a string first (strcat "W" [color=red](itoa[/color] num[color=red])[/color]) If the num variable were a real, then I would use rtos. Quote Link to comment Share on other sites More sharing options...
Sweety Posted August 24, 2010 Author Share Posted August 24, 2010 My two cents... If the num variable were a real, then I would use rtos. YES, Also a very good point. Thank you for interests. Sweety. Quote Link to comment Share on other sites More sharing options...
Lt Dan's legs Posted August 24, 2010 Share Posted August 24, 2010 If you didn't know... (cons 7 (getvar 'textstyle)) (cons 8 layer);;(setq layer "0") or whatever layer you wish If you do then ignore this post Quote Link to comment Share on other sites More sharing options...
BlackBox Posted August 24, 2010 Share Posted August 24, 2010 (edited) This may look a bit more involved, and it is, but I think you'll appreciate it in use. This routine does everything you originally posted, *and* accounts for text entities you've already added, incrementing from the largest "W#" already in the current drawing. This can be greatly improved (and done so easily) by adding layer (vla-put-layer ...), and style (vla-put-stylename ...) information, etc. as LT Dan's Legs has pointed out. Also, if you were to use MText instead of DText, additional options would become available to the text object such as justification (vla-put-attachmentpoint ...), etc. (defun c:WTEXT (/ pt num numList) (vl-load-com) (cond (*activeDoc*) ((setq *activeDoc* (vla-get-activedocument (vlax-get-acad-object))))) (prompt "\n >> Specify Multiple Insertion Points, <Enter> to Exit: ") (while (setq pt (getpoint)) (vla-addtext (cond (*modelSpace*) ((setq *modelSpace* (vla-get-modelspace *activeDoc*)))) (strcat "W" (itoa (cond (num (setq num (1+ num))) ((setq ss (ssget "_x" '((0 . "TEXT") (1 . "W*")))) (progn (vlax-for x (setq ss (vla-get-activeselectionset *activeDoc*)) (setq numList (cons (atoi (vl-string-left-trim "W" (vla-get-textstring x))) numList))) (vla-delete ss) (setq num (1+ (car (vl-sort numList '>)))))) (T (setq num 1))))) (vlax-3d-point pt) (getvar 'textsize))) (princ)) [edit] Corrected known "bad 3D point" error on exit. [/edit] Enjoy! :wink: Edited August 24, 2010 by BlackBox Corrected known error on exit. Quote Link to comment Share on other sites More sharing options...
Lee Mac Posted August 24, 2010 Share Posted August 24, 2010 Nice one Renderman, I like the way you use the COND statement I hope you don't mind, I would be inclined to write it like this: (defun c:wtext ( / spc doc p n ss ) (vl-load-com) (setq spc (if (or (eq AcModelSpace (vla-get-ActiveSpace (setq doc (vla-get-ActiveDocument (vlax-get-acad-object) ) ) ) ) (eq :vlax-true (vla-get-MSpace doc)) ) (vla-get-ModelSpace doc) (vla-get-PaperSpace doc) ) ) (terpri) (while (setq p (getpoint "\rPick Point <Exit>: ")) (vla-AddText spc (strcat "W" (itoa (setq n (cond (n (1+ n)) ( (setq ss (ssget "_X" '((0 . "TEXT") (1 . "W[0-9]*")))) ( (lambda ( i / e l s ) (while (setq e (ssname ss (setq i (1+ i)))) (if (eq "W" (vl-string-right-trim "0123456789" (setq s (cdr (assoc 1 (entget e)))))) (setq l (cons (atoi (substr s 2)) l)) ) ) (1+ (apply 'max l)) ) -1 ) ) ( 1 ) ) ) ) ) (vlax-3D-point (trans p 1 0)) (getvar 'textsize) ) ) (princ) ) I'm not saying yours is wrong Quote Link to comment Share on other sites More sharing options...
BlackBox Posted August 24, 2010 Share Posted August 24, 2010 Nice one Renderman, I like the way you use the COND statement I hope you don't mind...: Thanks Lee! I try not to turn down sounds advice, regardless of reputation. Besides, there are several things I really like about your routine over my own: Your use of nested setq's for the active document, and active space Your use of (1 . "W[0-9]*") Your use of vl-string-right-trim Your application of 'max to the list (I cannot believe I forgot about that one!) And, Finally, your translation from user coordinates to world. Brilliant! ... Although (and I hope you don't mind)... why define the spc variable at all? (defun c:wtext (/ [color=seagreen];| spc |;[/color] doc p n ss) (vl-load-com) (terpri) (while (setq p (getpoint "\rPick Point <Exit>: ")) (vla-AddText [color=red] (if[/color] [color=red] (or[/color] [color=red] (eq AcModelSpace[/color] [color=red] (vla-get-ActiveSpace[/color] [color=red] (setq doc[/color] [color=red] (vla-get-ActiveDocument[/color] [color=red] (vlax-get-acad-object)))))[/color] [color=red] (eq :vlax-true (vla-get-MSpace doc)))[/color] [color=red] (vla-get-ModelSpace doc)[/color] [color=red] (vla-get-PaperSpace doc))[/color] (strcat "W" (itoa (setq n (cond (n (1+ n)) ((setq ss (ssget "_X" '((0 . "TEXT") (1 . "W[0-9]*")))) ((lambda (i / e l s) (while (setq e (ssname ss (setq i (1+ i)))) (if (eq "W" (vl-string-right-trim "0123456789" (setq s (cdr (assoc 1 (entget e)))))) (setq l (cons (atoi (substr s 2)) l)))) (1+ (apply 'max l))) -1)) (1))))) (vlax-3D-point (trans p 1 0)) (getvar 'textsize))) (princ)) (Note - the formatting keeps getting distorted for some reason.) Cheers! Quote Link to comment Share on other sites More sharing options...
Lee Mac Posted August 24, 2010 Share Posted August 24, 2010 Your formatting is distorted as you may be inserting Tabs in the VLIDE formatting. - Make sure you switch this off under the Visual LISP formatting options. As for why I defined 'spc' : calling vlax-get-acad-object is slow and bad practice to be in a loop. Quote Link to comment Share on other sites More sharing options...
lpseifert Posted August 24, 2010 Share Posted August 24, 2010 Holy sh**... all the op wanted to know was how to strcat a string and a number! Quote Link to comment Share on other sites More sharing options...
BlackBox Posted August 24, 2010 Share Posted August 24, 2010 Your formatting is distorted as you may be inserting Tabs in the VLIDE formatting. - Make sure you switch this off under the Visual LISP formatting options. I'll do that. As for why I defined 'spc' : calling vlax-get-acad-object is slow and bad practice to be in a loop. Yes, of course. I've developed a code management system, for both programming and production tools, that I use in concert with established global vars... one of which being the active document. Sometimes, I forget best practices when writing a *full* routine for someone else, as I typically do not duplicate code where unnecessary. Quote Link to comment Share on other sites More sharing options...
BlackBox Posted August 24, 2010 Share Posted August 24, 2010 Holy sh**... all the op wanted to know was how to strcat a string and a number! You're welcome...?! Quote Link to comment Share on other sites More sharing options...
Lee Mac Posted August 24, 2010 Share Posted August 24, 2010 Holy sh**... all the op wanted to know was how to strcat a string and a number! Dude, we're all learning here, not just the OP :wink: Quote Link to comment Share on other sites More sharing options...
Lee Mac Posted August 24, 2010 Share Posted August 24, 2010 Yes, of course. I've developed a code management system, for both programming and production tools, that I use in concert with established global vars... one of which being the active document. Sometimes, I forget best practices when writing a *full* routine for someone else, as I typically do not duplicate code where unnecessary. Just making you aware. Quote Link to comment Share on other sites More sharing options...
BlackBox Posted August 24, 2010 Share Posted August 24, 2010 Just making you aware. I greatly appreciate that fact: "One who is offended by truth, has no place among those who seek wisdom" - Ah... Me (aka RenderMan) Quote Link to comment Share on other sites More sharing options...
alanjt Posted August 24, 2010 Share Posted August 24, 2010 eg. (setq num 0) (while (setq pt (getpoint "\nSpecify point: ")) (entmake (list '(0 . "TEXT") (cons 40 (getvar 'textsize)) (cons 1 (strcat "W" (rtos (setq num (1+ num)) 2 0))) (cons 10 (trans pt 1 0)) ) ) ) Quote Link to comment Share on other sites More sharing options...
BlackBox Posted August 24, 2010 Share Posted August 24, 2010 eg. (setq num 0) (while (setq pt (getpoint "\nSpecify point: ")) (entmake (list '(0 . "TEXT") (cons 40 (getvar 'textsize)) (cons 1 (strcat "W" (rtos (setq num (1+ num)) 2 0))) (cons 10 (trans pt 1 0)) ) ) ) ...And when you already have the first 12 ("W12") in the drawing? Quote Link to comment Share on other sites More sharing options...
alanjt Posted August 24, 2010 Share Posted August 24, 2010 ...And when you already have the first 12 ("W12") in the drawing?I was just following his entmake'ing. There's nothing wrong with what you and Lee posted. For the sake of posterity, I just wanted to give a simple entmake example. Quote Link to comment Share on other sites More sharing options...
BlackBox Posted August 24, 2010 Share Posted August 24, 2010 I was just following his entmake'ing. There's nothing wrong with what you and Lee posted. For the sake of posterity, I just wanted to give a simple entmake example. Understood; I didn't mean to dig at you, or your code for that matter... Besides, it's still a 'purty LISP, Alan (insert inside joke here). [edit] Hah! That's twice in two forums, in a single day! This one just happens to be a bit more 'twangy. [/edit] 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.