Is it possible to calculate the pt when creating text based on the width

Is it possible to calculate the pt when creating text based on the width

Anonymous
Not applicable
837 Views
5 Replies
Message 1 of 6

Is it possible to calculate the pt when creating text based on the width

Anonymous
Not applicable

I am new to lisp and trying to modify an existing lsp function to calculate the pt to use for the entmakex text based on the width of the textbox.  For a little background we are automating a lsp routine to take a drawing done in another software and convert it into autocad.  The challenge is that in the other system I know the width of the text box, the text value itself but I do not have access to the text size.  I have searched extensively and could not find anything but I may be using the wrong terminology in my searches.  Any assistance on where to look would be greatly appreciated!

0 Likes
Accepted solutions (1)
838 Views
5 Replies
Replies (5)
Message 2 of 6

Ranjit_Singh
Advisor
Advisor
Using textbox width and the value of the text should allow you to get the height of the box
(defun somefunc (textboxwidth textval / dat)
(setq dat (textbox (list '(0 . "text") (cons 1 textval) '(40 . 0.1))))
(* textboxwidth (/ 0.1 (abs (car (mapcar '- (car dat) (cadr dat)))))))
Although I am pretty sure the height should be available somewhere in the original program

0 Likes
Message 3 of 6

john.uhden
Mentor
Mentor

@Ranjit_Singh is correct as usual.  But whether you know the source's height or not, you will probably want to make it the height of your choice, yes?  For example, your drawing scale or linear units may be very different.  You could just use the Properties dialog to change them all (Ctrl+1).

John F. Uhden

0 Likes
Message 4 of 6

Anonymous
Not applicable

Ranjit thanks for the suggested code.  When running the function I am getting a response of  error: bad function:  Below is the function I wrote based on your input.

 

 

(defun def_findhgt (textboxwidth textval / dat)
(setq dat (textbox (list '(0 . "text") (cons 1 textval) '(40 . 0.1))))
(* textboxwidth (/ 0.1 (abs (car (mapcar '- (car dat) (cadr dat))))))
)

 

I am passing in 1637 as the textboxwidth and "Sample Text Display" as the textval.

 

 

0 Likes
Message 5 of 6

Ranjit_Singh
Advisor
Advisor
Accepted solution

works for me

Command: (defun def_findhgt (textboxwidth textval / dat)
(_> (setq dat (textbox (list '(0 . "text") (cons 1 textval) '(40 . 0.1))))
(_> (* textboxwidth (/ 0.1 (abs (car (mapcar '- (car dat) (cadr dat))))))
(_> )
DEF_FINDHGT
Command: (def_findhgt 1637 "Sample Text Display")
118.623
0 Likes
Message 6 of 6

Anonymous
Not applicable

I was trying to print directly rather than setting the variable from the function first and then printing.  Thanks so much for your help!

0 Likes