Jump to content

How to goin tow Variables


Tharwat

Recommended Posts

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

Link to comment
Share on other sites

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. >

Link to comment
Share on other sites

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

Link to comment
Share on other sites

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)
)

Link to comment
Share on other sites

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

Link to comment
Share on other sites

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

Link to comment
Share on other sites

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:

Link to comment
Share on other sites

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

Link to comment
Share on other sites

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

 

 "111\"x222"

Link to comment
Share on other sites

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. :roll:

 

Many Thanks

Tharwat

Link to comment
Share on other sites

So Can I know your alternative suggestion instead of strcat in this case. :roll:

 

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.
Link to comment
Share on other sites

 "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

Link to comment
Share on other sites

Hello,

So here is the result of giving variables numerical values.

it is just the beginning .

 

Thanks for all Participants.

Specially to alanjt.

 

Tharwat

texts.jpg

Link to comment
Share on other sites

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.

Guest
Unfortunately, your content contains terms that we do not allow. Please edit your content to remove the highlighted words below.
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...