TheSwamp

Code Red => AutoLISP (Vanilla / Visual) => Topic started by: MeasureUp on May 17, 2017, 10:29:18 PM

Title: To have or not to have (quotation mark)
Post by: MeasureUp on May 17, 2017, 10:29:18 PM
This is really a basic question but...

In "text" command, I notice there is no difference between two lines. They all create text without error message:
(command "._text" "justify" "ML" (getpoint "\n\nPick a point: ") 15 0 (strcat "A" "B" "C"))
(command "._text" "justify" "ML" (getpoint "\n\nPick a point: ") "15" "0" (strcat "A" "B" "C"))

Can you tell which is correct and why.

Thank you.
Title: Re: To have or not to have (quotation mark)
Post by: kdub_nz on May 17, 2017, 11:51:44 PM

What is your criteria for 'correct' ??
Title: Re: To have or not to have (quotation mark)
Post by: MeasureUp on May 18, 2017, 12:29:41 AM
Thanks for your reply.
Because the inputs of text size and rotation angle are numbers (not strings), IMO they should be filled in without quotation marks.
I have used it for long time without any problems.

When you write this "text" command line in code, do you think the use of "" is appropriated? e.g.
(command "._text" "justify" "ML" (getpoint "\n\nPick a point: ") "15" "0" (strcat "A" "B" "C"))

However, by reading threads in other website, I found either with "" or not, both work without problems.
Title: Re: To have or not to have (quotation mark)
Post by: irneb on May 18, 2017, 01:44:26 AM
In this particular case it really doesn't matter. Both do pretty much the same thing. You can see the quotation mark idea as if sending keystrokes to the command-line, while the sending integer values idea "may" send the value directly or it may first convert it to a string in any case. I'm not exactly sure how ACad has implemented this, my guess would be that it converts to text - would make the command line interactions easier to program on their side.

If this is the case, then sending a fractional number may vary from machine to machine. Depending on how many fractional points are set to be displayed. In which case sending a text string becomes more controllable from the code's side. If it's not the case (and ACad actually just sends the number value direct into the command without conversions) then the number idea would be the most accurate.


Of course, just entering such direct constant values isn't very interesting. It's when those values come from some variable when this makes a bit of difference. Do you just send a fraction value direct? Or do you convert it using something like rtos so you can control the accuracy?

Personally I've not bothered too much - it seems to work fine for those cases where I had to use the command line interface (doesn't happen often). I generally prefer using direct function calls instead of sending to command-line anyway (if at all possible), either through such methods as entmake/entmod or through vla. None of this "guessing" what happens, tends to run a LOT faster, and is able to be done through ObjectDBX on non-current DWG files as well.
Title: Re: To have or not to have (quotation mark)
Post by: MeasureUp on May 18, 2017, 02:13:09 AM
In this particular case it really doesn't matter. Both do pretty much the same thing. You can see the quotation mark idea as if sending keystrokes to the command-line, while the sending integer values idea "may" send the value directly or it may first convert it to a string in any case. I'm not exactly sure how ACad has implemented this, my guess would be that it converts to text - would make the command line interactions easier to program on their side.

If this is the case, then sending a fractional number may vary from machine to machine. Depending on how many fractional points are set to be displayed. In which case sending a text string becomes more controllable from the code's side. If it's not the case (and ACad actually just sends the number value direct into the command without conversions) then the number idea would be the most accurate.


Of course, just entering such direct constant values isn't very interesting. It's when those values come from some variable when this makes a bit of difference. Do you just send a fraction value direct? Or do you convert it using something like rtos so you can control the accuracy?

Personally I've not bothered too much - it seems to work fine for those cases where I had to use the command line interface (doesn't happen often). I generally prefer using direct function calls instead of sending to command-line anyway (if at all possible), either through such methods as entmake/entmod or through vla. None of this "guessing" what happens, tends to run a LOT faster, and is able to be done through ObjectDBX on non-current DWG files as well.

Thank you so much irneb.
The reason I rose this question was wanted to keep my mind clear when writing codes.
Personally speaking, it will be very easily to misapply function definitions from line to line, especially when writing long piece of code.

The examples here are certainly for this question only and entmake/entmod would be better to apply in code.
Thanks again.
Title: Re: To have or not to have (quotation mark)
Post by: irneb on May 18, 2017, 07:41:24 AM
Personally speaking, it will be very easily to misapply function definitions from line to line, especially when writing long piece of code.
Personally speaking  ;)  I see no difference between misapplying a function's arguments and the command-line options. In both cases it becomes a lookup in some help documentation to find out what inputs are required and in what order.
Title: Re: To have or not to have (quotation mark)
Post by: Grrr1337 on May 18, 2017, 08:27:26 AM
You could error-trap, which is not advised usually:

Code: [Select]
(or
  (not (vl-catch-all-error-p (vl-catch-all-apply 'command '("._text" "justify" "ML" (getpoint "\n\nPick a point: ") 15 0 (strcat "A" "B" "C")))))
  (not (vl-catch-all-error-p (vl-catch-all-apply 'command '("._text" "justify" "ML" (getpoint "\n\nPick a point: ") "15" "0" (strcat "A" "B" "C")))))
)
Title: Re: To have or not to have (quotation mark)
Post by: ronjonp on May 18, 2017, 09:36:24 AM
Why not use entmake?
Code - Auto/Visual Lisp: [Select]
  1. (defun _maketext (point string width rotation layer)
  2.   (if point
  3.     (entmakex (list '(0 . "TEXT")
  4.                     '(100 . "AcDbEntity")
  5.                     (cons 8 layer)
  6.                     '(100 . "AcDbText")
  7.                     (cons 10 (trans point 1 0))
  8.                     '(40 . 60.0)
  9.                     (cons 1 string)
  10.                     (cons 50 rotation)
  11.                     (cons 41 width)
  12.                     '(72 . 1)
  13.                     (cons 11 (trans point 1 0))
  14.                     '(73 . 2)
  15.               )
  16.     )
  17.   )
  18. )
  19. ;; (_maketext (getpoint) "Hello World!" 0.75 (angtof "45") "Text")