Author Topic: To have or not to have (quotation mark)  (Read 1760 times)

0 Members and 1 Guest are viewing this topic.

MeasureUp

  • Bull Frog
  • Posts: 462
To have or not to have (quotation mark)
« 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.

kdub_nz

  • Mesozoic keyThumper
  • SuperMod
  • Water Moccasin
  • Posts: 2125
  • class keyThumper<T>:ILazy<T>
Re: To have or not to have (quotation mark)
« Reply #1 on: May 17, 2017, 11:51:44 PM »

What is your criteria for 'correct' ??
Called Kerry in my other life
Retired; but they dragged me back in !

I live at UTC + 13.00

---
some people complain about loading the dishwasher.
Sometimes the question is more important than the answer.

MeasureUp

  • Bull Frog
  • Posts: 462
Re: To have or not to have (quotation mark)
« Reply #2 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.

irneb

  • Water Moccasin
  • Posts: 1794
  • ACad R9-2016, Revit Arch 6-2016
Re: To have or not to have (quotation mark)
« Reply #3 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.
Common sense - the curse in disguise. Because if you have it, you have to live with those that don't.

MeasureUp

  • Bull Frog
  • Posts: 462
Re: To have or not to have (quotation mark)
« Reply #4 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.

irneb

  • Water Moccasin
  • Posts: 1794
  • ACad R9-2016, Revit Arch 6-2016
Re: To have or not to have (quotation mark)
« Reply #5 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.
Common sense - the curse in disguise. Because if you have it, you have to live with those that don't.

Grrr1337

  • Swamp Rat
  • Posts: 812
Re: To have or not to have (quotation mark)
« Reply #6 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")))))
)
(apply ''((a b c)(a b c))
  '(
    (( f L ) (apply 'strcat (f L)))
    (( L ) (if L (cons (chr (car L)) (f (cdr L)))))
    (72 101 108 108 111 32 87 111 114 108 100)
  )
)
vevo.bg

ronjonp

  • Needs a day job
  • Posts: 7526
Re: To have or not to have (quotation mark)
« Reply #7 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")

Windows 11 x64 - AutoCAD /C3D 2023

Custom Build PC