Author Topic: Length of a string  (Read 6207 times)

0 Members and 1 Guest are viewing this topic.

velasquez

  • Newt
  • Posts: 195
Length of a string
« on: August 12, 2014, 05:40:54 PM »
I need to convert the length of a string (strlen "nononododod") for drawing units.
I know that the source will always .shx
I also know the height of the font.

The best way would be to compare a pattern?
Does anyone know a faster way?

Thanks

Keith™

  • Villiage Idiot
  • Seagull
  • Posts: 16899
  • Superior Stupidity at its best
Re: Length of a string
« Reply #1 on: August 12, 2014, 06:11:36 PM »
Try something like this:

Code: [Select]
(car (cadr (textbox (entget (car (entsel))))))
Proud provider of opinion and arrogance since November 22, 2003 at 09:35:31 am
CadJockey Militia Field Marshal

Find me on https://parler.com @kblackie

Lee Mac

  • Seagull
  • Posts: 12906
  • London, England
Re: Length of a string
« Reply #2 on: August 12, 2014, 06:22:11 PM »
Or something along the lines of:

Code - Auto/Visual Lisp: [Select]
  1. (   (lambda ( box ) (- (caadr box) (caar box)))
  2.     (textbox
  3.         (list
  4.             (cons 01 str)
  5.             (cons 40 hgt)
  6.             (cons 07 sty)
  7.         )
  8.     )
  9. )

velasquez

  • Newt
  • Posts: 195
Re: Length of a string
« Reply #3 on: August 12, 2014, 06:33:05 PM »
Excuse the language confuses me.
I still have the text in the drawing.

danallen

  • Guest
Re: Length of a string
« Reply #4 on: August 12, 2014, 06:49:36 PM »
do you mean height instead of length? please show a picture

velasquez

  • Newt
  • Posts: 195
Re: Length of a string
« Reply #5 on: August 12, 2014, 07:12:11 PM »
I have a list of strings.
I need to draw a box to write strings inside.
Code: [Select]
(("Válvula de gaveta c/ flanges e cunha de borracha corpo longo c/ volante Euro 21") ("Válvula de gaveta c/ flanges Euro 21"))

I know the height of the font and the type -> can be "romans.shx" or "simplex.shx" or any other font .shx

dgorsman

  • Water Moccasin
  • Posts: 2437
Re: Length of a string
« Reply #6 on: August 13, 2014, 11:38:48 AM »
Since there isn't a logical difference between adding text into a box that has been calculated to fit the text, and drawing the calculated box around the text, I'd suggest the latter.

If the box is somehow fixed in size, then you've got different problem.
If you are going to fly by the seat of your pants, expect friction burns.

try {GreatPower;}
   catch (notResponsible)
      {NextTime(PlanAhead);}
   finally
      {MasterBasics;}

ronjonp

  • Needs a day job
  • Posts: 7526
Re: Length of a string
« Reply #7 on: August 13, 2014, 11:51:28 AM »
Why not just use a table?

Windows 11 x64 - AutoCAD /C3D 2023

Custom Build PC

velasquez

  • Newt
  • Posts: 195
Re: Length of a string
« Reply #8 on: August 13, 2014, 02:58:29 PM »
Why not just use a table?

Hi ronjonp
Your idea is very good but I have no experience drawing tables.
I have the standard design for the table.
The user chose the font height and font .shx
Example -> font height = 5
                   font type    = romans.shx

My idea was to design a table using any other command with the information I have.

I appreciate any help.

ronjonp

  • Needs a day job
  • Posts: 7526
Re: Length of a string
« Reply #9 on: August 13, 2014, 03:20:15 PM »
Look into the TABLESTYLE command. Alternatively if you're going to draw the table use the code Lee supplied to get the width of the string.

Windows 11 x64 - AutoCAD /C3D 2023

Custom Build PC

velasquez

  • Newt
  • Posts: 195
Re: Length of a string
« Reply #10 on: August 13, 2014, 03:33:26 PM »
Look into the TABLESTYLE command. Alternatively if you're going to draw the table use the code Lee supplied to get the width of the string.
Thank you ron.

velasquez

  • Newt
  • Posts: 195
Re: Length of a string
« Reply #11 on: August 13, 2014, 04:26:37 PM »
Or something along the lines of:

Code - Auto/Visual Lisp: [Select]
  1. (   (lambda ( box ) (- (caadr box) (caar box)))
  2.     (textbox
  3.         (list
  4.             (cons 01 str)
  5.             (cons 40 hgt)
  6.             (cons 07 sty)
  7.         )
  8.     )
  9. )

Hi Lee,
Your tip helped me a lot again,.
thanks.



Lee Mac

  • Seagull
  • Posts: 12906
  • London, England
Re: Length of a string
« Reply #12 on: August 14, 2014, 01:53:35 PM »
Or something along the lines of:

Code - Auto/Visual Lisp: [Select]
  1. (   (lambda ( box ) (- (caadr box) (caar box)))
  2.     (textbox
  3.         (list
  4.             (cons 01 str)
  5.             (cons 40 hgt)
  6.             (cons 07 sty)
  7.         )
  8.     )
  9. )

Hi Lee,
Your tip helped me a lot again,.
thanks.

You're welcome  :-)

Regarding the table - my LM:addtable function from my Polyline Information program may help you.

Lee

velasquez

  • Newt
  • Posts: 195
Re: Length of a string
« Reply #13 on: August 14, 2014, 05:25:58 PM »
Or something along the lines of:

Code - Auto/Visual Lisp: [Select]
  1. (   (lambda ( box ) (- (caadr box) (caar box)))
  2.     (textbox
  3.         (list
  4.             (cons 01 str)
  5.             (cons 40 hgt)
  6.             (cons 07 sty)
  7.         )
  8.     )
  9. )

Hi Lee,
Your tip helped me a lot again,.
thanks.

You're welcome  :-)

Regarding the table - my LM:addtable function from my Polyline Information program may help you.

Lee

Its function will help me a lot
Against the table you can create an image attached equal to, or similar?

dgorsman

  • Water Moccasin
  • Posts: 2437
Re: Length of a string
« Reply #14 on: August 14, 2014, 05:44:30 PM »
If those "fixed size" and "variable size" refer to column width, you have a logical problem: the header over the last "variable" column is indicated as "fixed", so with all the other child columns also "fixed" the last column cannot be variable.
If you are going to fly by the seat of your pants, expect friction burns.

try {GreatPower;}
   catch (notResponsible)
      {NextTime(PlanAhead);}
   finally
      {MasterBasics;}