Jump to content
mstb

Find the length of a text

Recommended Posts

mstb

hello every one

I want to find the length of a text I don't mean the number of characters, for example every text has a height and length I want that length

Thanks all

Share this post


Link to post
Share on other sites
BIGAL

Not exact depends on font (/ (* (strlen str)  ht) 1.4) ? It varies for say IIIIIII and WWWWWWW

Share this post


Link to post
Share on other sites
mstb

Thank you very much

Share this post


Link to post
Share on other sites
dlanorh
1 hour ago, mstb said:

hello every one

I want to find the length of a text I don't mean the number of characters, for example every text has a height and length I want that length

Thanks all

 

Is the text already in the drawing or in a lisp

Share this post


Link to post
Share on other sites
mstb
Posted (edited)

yes It is in the drawing

I actually want to transfer the elevation codes that are in the drawing  so that the insertion point falls on the dot point

Of course, this way I have to use the right font, which is a problem (I mean, the font that gives a space to all the characters)

excuse me for may bad english

Edited by mstb

Share this post


Link to post
Share on other sites
eldon
22 minutes ago, mstb said:

........so that the insertion point falls on the dot point

 

It would be very handy if AutoCAD provided a dot justification. But the length of the text is not all that helpful, as elevation texts can have varying number of digits before the decimal point.

Share this post


Link to post
Share on other sites
mstb
Posted (edited)
31 minutes ago, eldon said:

 

It would be very handy if AutoCAD provided a dot justification. But the length of the text is not all that helpful, as elevation texts can have varying number of digits before the decimal point.

Exactly . First, I wanted to break the elevation code into three parts, one before and one last, almost self-contained and in the right position, but now I had three texts that I wanted to put together as if I were back in the first place.

(defun c:s ()
  (setq ss (ssget '((0 . "TEXT"))))
  (setq n (sslength ss))
  (setq li nil)
  (setq k -1)
  (repeat n
    (setq k (1+ k))
    (setq s (ssname ss k))
    (setq en (entget s))
    (setq ang (cdr (assoc 50 en)))
    (setq hi (cdr (assoc 40 en)))
    (setq la (cdr (assoc 8 en)))
    (setq po (cdr (assoc 11 en)))
    (setq txt (cdr (assoc 1 en)))
    (setq m (strlen txt))
    (setq d1 "")
    (setq d2 "")
    (setq i 0)
    (setq j 1)
    (repeat m
      (setq i (1+ i))
      (setq let (substr txt i 1))
      (if (/= let ".")
	(cond
	  ((= j 1) (setq d1 (strcat d1 let)))
	  ((= j 2) (setq d2 (strcat d2 let)))
	)
	(setq j (1+ j))
      )
      )
      (setq li (append li (list (list d1 d2))))
      )


    (entmake (list
	       (cons 0 "TEXT")
	       (cons 8 "la")
	       (cons 72 2)
	       (cons 73 0)
	       (cons 1 d1)
	       (cons 10 po)
	       (cons 11 po)
	       (cons 40 hi)
	       (cons 50 ang)
	     )
    )
      (entmake (list
	       (cons 0 "TEXT")
	       (cons 8 "la")
	       (cons 72 1)
	       (cons 73 0)
	       (cons 1 ".")
	       (cons 10 po)
	       (cons 11 po)
	       (cons 40 hi)
	       (cons 50 ang)
	     )
    )
    (entmake (list
	       (cons 0 "TEXT")
	       (cons 8 "la")
	       (cons 72 0)
	       (cons 73 0)
	       (cons 1 d2)
	       (cons 10 po)
	       (cons 11 po)
	       (cons 40 hi)
	       (cons 50 ang)
	     )
    )

  (princ)
)

It 's ok . But now I have three texts!

Edited by mstb

Share this post


Link to post
Share on other sites
dlanorh
43 minutes ago, mstb said:

yes It is in the drawing

I actually want to transfer the elevation codes that are in the drawing  so that the insertion point falls on the dot point

Of course, this way I have to use the right font, which is a problem (I mean, the font that gives a space to all the characters)

excuse me for may bad english

 

Look at Courier New or Monospac821BT

Share this post


Link to post
Share on other sites
mstb
4 minutes ago, dlanorh said:

 

Look at Courier New or Monospac821BT

yes. Thanks.But it would have been much better if I hadn't changed the font

Share this post


Link to post
Share on other sites
eldon

Perhaps this thread might provide food for thought

Share this post


Link to post
Share on other sites
mstb
8 minutes ago, eldon said:

Perhaps this thread might provide food for thought

Thank you very much

Share this post


Link to post
Share on other sites
BIGAL

30 year old civil design software did this not Autocad it had an option the decimal point was on the point. If the insertion point is one of the 9 points available pretty easy to move text. Maybe C-C if you want the decimal point then yes a problem. Like Dlanorh look at a monospaced font. 

 

Post an image of what you want.

Share this post


Link to post
Share on other sites
mstb
2 hours ago, BIGAL said:

30 year old civil design software did this not Autocad it had an option the decimal point was on the point. If the insertion point is one of the 9 points available pretty easy to move text. Maybe C-C if you want the decimal point then yes a problem. Like Dlanorh look at a monospaced font. 

 

Post an image of what you want.

Thank you very much

Share this post


Link to post
Share on other sites
mstb

Where is wrong؟!!!

(command "STYLE" "new" "italic" "" "" "" "" "" "")  It's ok

(command "STYLE" "new" "Monospac821 BT" "" "" "" "" "" "") But This one ?!!!!

Share this post


Link to post
Share on other sites
BIGAL

Try this

 

(entmake
'( (0 . "STYLE")
(100 . "AcDbSymbolTableRecord")
(100 . "AcDbTextStyleTableRecord")
(2 . "Mono")
(70 . 0)
(40 . 0.0)
(41 . 1.0)
(50 . 0.0)
(71 . 0)
(3 . "Monospac821 BT.TTF")
(4 . "")
)
)

 

Share this post


Link to post
Share on other sites
dlanorh
3 hours ago, mstb said:

Where is wrong؟!!!

(command "STYLE" "new" "italic" "" "" "" "" "" "")  It's ok

(command "STYLE" "new" "Monospac821 BT" "" "" "" "" "" "") But This one ?!!!!

 

If you are going to use MonoSpac821 BT, I already have a lisp that returns the approximate middle of the dot (decimal point). It's scales OK, but was primally written to work with drawings in metres (text sizes less than 1.0)

Share this post


Link to post
Share on other sites
mstb
1 hour ago, BIGAL said:

Try this

 


(entmake
'( (0 . "STYLE")
(100 . "AcDbSymbolTableRecord")
(100 . "AcDbTextStyleTableRecord")
(2 . "Mono")
(70 . 0)
(40 . 0.0)
(41 . 1.0)
(50 . 0.0)
(71 . 0)
(3 . "Monospac821 BT.TTF")
(4 . "")
)
)

 

Thank you very much

Share this post


Link to post
Share on other sites
mstb
2 minutes ago, dlanorh said:

 

If you are going to use MonoSpac821 BT, I already have a lisp that returns the approximate middle of the dot (decimal point). It's scales OK, but was primally written to work with drawings in metres (text sizes less than 1.0)

Thank you very much

Share this post


Link to post
Share on other sites
dlanorh
1 hour ago, BIGAL said:

Try this

 


(entmake
'( (0 . "STYLE")
(100 . "AcDbSymbolTableRecord")
(100 . "AcDbTextStyleTableRecord")
(2 . "Mono")
(70 . 0)
(40 . 0.0)
(41 . 1.0)
(50 . 0.0)
(71 . 0)
(3 . "Monospac821 BT.TTF")
(4 . "")
)
)

 

 

Stop stealing my Mono textstyle. :danger::lol:

Share this post


Link to post
Share on other sites
Lee Mac

There is no need to create temporary text objects, nor guess the width using the number of characters and a factor, just use the textbox AutoLISP function.

Share this post


Link to post
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
Reply to this topic...

×   Pasted as rich text.   Paste as plain text instead

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