Anuncios

The Autodesk Community Forums has a new look. Read more about what's changed on the Community Announcements board.

Anonymous
1170 Vistas, 8 Respuestas

Lisp Routine Create a variable size rectangle with centered text

Hello,
I'm hoping to find a lsp to create a rectangle with a variable size and allow me to write text inside it and center the text.

Thanks for the help.

Etiquetas (1)
CodeDing
en respuesta a: Anonymous

@Anonymous ,

 

This sounds like an ideal scenario for a block. Have you considered that route? If that does not work can you elaborate as to why?

 

Best

~DD

devitg
en respuesta a: Anonymous

@Anonymous Or you mean , draw a rectangle around any text drawn 

Kent1Cooper
en respuesta a: Anonymous

In simplest terms, here's one way:

 

(defun C:TEST (/ pt1 pt2)
  (command
    "_.rectang"
    (setq pt1 (getpoint "\nCorner of rectangle: "))
    (setq pt2 (getcorner pt1 "\nOpposite corner: "))
    "_.dtext" "_mc" "_m2p" pt1 pt2 "" ""
  ); command
  (princ)
)

 

It assumes you want to draw the rectangle by simple opposite corners, and not call for any of the options within this routine [filleted corners, etc.], and that the Text would be at 0° rotation and in whatever the current Style is, and that Style does not have a fixed height.  Variations in such things can be accounted for.

Kent Cooper, AIA
devitg
en respuesta a: Kent1Cooper

@Kent1Cooper , hi Kent , what about I want the text to fill the rectangle .

I try with this code 

 

 (setq rect-heigth  ( * (distance pt1 pt2) (sin (angle pt1 pt2))))
(setq text-height (*  0.80 rect-heigth))
(setq text-obj (vlax-ename->vla-object  (entlast)))
(vla-put-Height text-obj text-height)

But it exceed the rectangle wide . I test with 0.80 the rectangle height , but it depend from the how much  characters   has te text .  

Thanks in advance 

 

 

jtohill
en respuesta a: Anonymous

You can also just turn on the text frame for your mtext that has justification set to be middle centered.

CodeDing
en respuesta a: devitg

@devitg ,

 

If you are using a TEXT entity, you can set the Justification to "FIT".. Then just make sure the Insertion Point, Alignment Point, and height are all appropriate, that will keep long text inside your rectangle.

 

Best,

~DD

ara_neresesian
en respuesta a: Anonymous

HI

you can use tcircle from express tools 

1-  tcircle 

2-select object/s.

3-enter your offset ( gap between text and rectangle )

4- rectangle

5- Variable

 

good luck

 

 

 

Kent1Cooper
en respuesta a: Anonymous

 


@Anonymous wrote:

.... to create a rectangle with a variable size and allow me to write text inside it and center the text. ....


Clarify something for us....

 

Several suggestions here are about a relationship between the size of the Text and the size of the rectangle, with either the rectangle determining the size of the Text [the Fit-justification approach] or the other way around [the Mtext-with-frame and TCIRCLE approaches].  That's not part of your original request, but is that something you need?  If so, which one should determine the size of the other, and in what way?

Kent Cooper, AIA