Tharwat Posted June 17, 2010 Posted June 17, 2010 Hello everybody, (defun c:abc (/ a b c)(setq a 111) (setq b 222) (setq c (strcat a "x" b)) (command "_text" pause "" "" c "") (princ) ) The outcome must be 111x222 as a text but it respond nil . .... Why? regards, Tharwat Quote
Freerefill Posted June 17, 2010 Posted June 17, 2010 The reason the text wasn't created was because your variables a and b are not strings, they are numbers. You can only pass string arguments to strcat. You can change the numbers to strings using: (itoa 123) for integers (numbers without a decimal point) or (rtos 123.123 2 3) for real numbers or floating point numbers (numbers with a decimal point) EDIT: Reversed my *to* functions.. I always do that.. it's correct now. > Quote
Tharwat Posted June 17, 2010 Author Posted June 17, 2010 Thanks Lee. The codes that I have provided are a part of a medium sized Lisp, and to use entmakethat would tighten the program and would be crowded with entmaks function. So why strcat function is not responding since it is used correctly ? Thanks a lot Quote
alanjt Posted June 17, 2010 Posted June 17, 2010 While I agree with Lee on using entmake, especially for text, your problem lies with trying to join 3 items that are supposed to be text where variables a and b are not. eg. (defun c:abc (/ a b c) (setq a [color=Red]"111"[/color]) (setq b [color=Red]"222"[/color]) (setq c (strcat a "x" b)) (command "_text" pause "" "" c "") (princ) ) entmake eg. (defun c:abc (/ a b c pt) (setq a "111") (setq b "222") (setq c (strcat a "x" b)) (if (setq pt (getpoint "\nSpecify placement point: ")) (entmake (list '(0 . "TEXT") (cons 40 (getvar 'textsize)) (cons 10 (trans pt 1 0)) (cons 1 c) ) ) ) (princ) ) Quote
Tharwat Posted June 17, 2010 Author Posted June 17, 2010 The reason the text wasn't created was because your variables a and b are not strings, they are numbers. You can only pass string arguments to strcat. You can change the numbers to strings using: (itoa 123) for integers (numbers without a decimal point) or (rtos 123.123 2 3) for real numbers or floating point numbers (numbers with a decimal point) EDIT: Reversed my *to* functions.. I always do that.. it's correct now. > Thanks a lot. But giving numbers to variables can not be considered wrong , And there is no need to use (itoa , rots ....so on ) and here is an example .... try it; (defun c:abc (/ a ) (setq a 111) (command "_text" pause "" "" a "") (princ) ) It works well Regards. Tharwat Quote
Tharwat Posted June 17, 2010 Author Posted June 17, 2010 While I agree with Lee on using entmake, especially for text, your problem lies with trying to join 3 items that are supposed to be text where variables a and b are not. eg. (defun c:abc (/ a b c) (setq a [color=Red]"111"[/color]) (setq b [color=Red]"222"[/color]) (setq c (strcat a "x" b)) (command "_text" pause "" "" c "") (princ) ) entmake eg. (defun c:abc (/ a b c pt) (setq a "111") (setq b "222") (setq c (strcat a "x" b)) (if (setq pt (getpoint "\nSpecify placement point: ")) (entmake (list '(0 . "TEXT") (cons 40 (getvar 'textsize)) (cons 10 (trans pt 1 0)) (cons 1 c) ) ) ) (princ) ) That was great Mr.alanjt both are perfect. Thank you sooooooooooo much Tharwat Quote
alanjt Posted June 17, 2010 Posted June 17, 2010 Thanks a lot.But giving numbers to variables can not be considered wrong , And there is no need to use (itoa , rots ....so on ) and here is an example .... try it; (defun c:abc (/ a ) (setq a 111) (command "_text" pause "" "" a "") (princ) ) It works well Regards. Tharwat Sending numbers to command won't screw things up, but try and join anything (using strcat, as you did above) or use entmake/vla-addtext and you'll receive an error. :wink: Quote
Tharwat Posted June 17, 2010 Author Posted June 17, 2010 Mr.alanjt how to have a text in inches for example 111"x222" .I have tried this for so many times but the result was nil. Could you please give me your idea. Regards. Tharwat Quote
alanjt Posted June 17, 2010 Posted June 17, 2010 Mr.alanjthow to have a text in inches for example 111"x222" .I have tried this for so many times but the result was nil. Could you please give me your idea. Regards. Tharwat "111\"x222" Quote
Tharwat Posted June 17, 2010 Author Posted June 17, 2010 Sending numbers to command won't screw things up, but try and join anything (using strcat, as you did above) or use entmake/vla-addtext and you'll receive an error. :wink: So Can I know your alternative suggestion instead of strcat in this case. Many Thanks Tharwat Quote
alanjt Posted June 17, 2010 Posted June 17, 2010 So Can I know your alternative suggestion instead of strcat in this case. Many Thanks Tharwat Convert your integer (what you provided with 111 and 222) to a string with vl-princ-to-string, itoa or rtos and combine. Quote
Tharwat Posted June 17, 2010 Author Posted June 17, 2010 "111\"x222" (defun c:abc (/ a b c) (setq a "111\"x222") (command "_text" pause "" "" a "") (princ) ) result; 111"x222 That's will be oki .... but for the first number, So what about the second number like this ; 111"x222" Thanks. Tharwat Quote
Tharwat Posted June 17, 2010 Author Posted June 17, 2010 Come on man... "111\"x222\"" Thanks again and again ... it's Beautiful. All respects. Tharwat Quote
alanjt Posted June 17, 2010 Posted June 17, 2010 Thanks again and again ... it's Beautiful. All respects. Tharwat Just messing with you. Quote
Tharwat Posted June 17, 2010 Author Posted June 17, 2010 Hello, So here is the result of giving variables numerical values. it is just the beginning . Thanks for all Participants. Specially to alanjt. Tharwat 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.