Problem - Lisp Routine Using Textbox Command

I have a lisp routine that draws a balloon (elongated if necessary) around a single line of text.
Because of the variable nature of text (font style, width, obliquing angle,
etc.), I wanted some means of measuring the length of the user entered textline so I could accurately calculate whether the balloon needed elongating, and if so, by how much. I also wanted to pick up the *exact* centre of the textline (allowing for risers, descenders, font width, obliquing angle, etc.) and then place the textline exactly centre of the balloon.
The only way I can find of accurately measuring the textline is to use the Textbox command.
I initially draw the textline off-screen, apply Textbox and then use the Textbox returned diagonal coordinates to calculate the length of the textline (as a distance) and the exact centre of the textline (as a point). The textline is then moved from its off-screen position to the centre of the balloon.
Textbox returns its bounding box points (lower left, upper right) as if the textline's insertion point were located at (0, 0, 0), although this seems to assume Left justified text and I am using MC justified text. Because of this, I have to translate the textline 'exact centre' point. At the moment I achieve this by setting the UCS to the text object and using:
(trans <text-centre-point> 1 0) followed by (command "UCS" "P")
This translates the point from the current (object) UCS to the World UCS.
I'm not sure if this is the best way to achieve what I want. Also, the routine will fail if the user is not in the World UCS when the lisp routine is run.
I thought I might check to see what the current UCS is, but cannot find a command to give me this information. UCSNAME returns " " when in World.
Can anyone suggest a better way to calculate the 'exact centre' point and then move the text by that point to the balloon centre, possibly without using Trans?
Thanks
--
Mike
-Please remove 'safetycatch' from e-mail address before firing off your
  Click to see the full signature.
Add pictures here
<% if( /^image/.test(type) ){ %>
<% } %>
<%-name%>
Add image file
Upload
When you extract the text's data using (entget <text-ename>), the tag 11 gives you the exact coordinate of the text's center point if this text was added in Mid-center justification.
This may help!
mlv a crit :

Add pictures here
<% if( /^image/.test(type) ){ %>
<% } %>
<%-name%>
Add image file
Upload
Marcel Aubin wrote:

Thanks for the advice.
The Assoc 11 coordinate is not always the *exact* Mid-Centre of the textline if, for example, the textstyle has been obliqued. However, it is generally close enough :-)
At the moment my Lisp routine still calculates the true Middle-Centre of the textline using the 'Textbox' function coordinates and then applying the trans function.
I discovered that I could overcome the routine failing if the user is not in the World UCS when the lisp routine is run by using:
(command "UCS" "Object" <text-entity>) (setq tmcp (trans <true-middle-centre-point> 1 0)) (command "UCS" "P") (setq tmcp (trans tmcp 0 1))
Note: tmcp = True Middle-Centre Point
The first trans function translates the text <true-middle-centre-point> (calculated from the Textbox coordinates) from the Text Object UCS to the World UCS and saves it to the variable tmcp
The second trans function translates tmcp from the World UCS to User UCS, in case the World UCS is NOT the current UCS. If the World UCS is in fact the current UCS, the trans function returns the coordinates unchanged.
It seems to work OK.
--
Mike
-Please remove 'safetycatch' from e-mail address before firing off your
  Click to see the full signature.
Add pictures here
<% if( /^image/.test(type) ){ %>
<% } %>
<%-name%>
Add image file
Upload

Polytechforum.com is a website by engineers for engineers. It is not affiliated with any of manufacturers or vendors discussed here. All logos and trade names are the property of their respective owners.