Anuncios

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

Lisp Routine Create a variable size rectangle with centered text

Anonymous

Lisp Routine Create a variable size rectangle with centered text

Anonymous
No aplicable

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.

0 Me gusta
Responder
Soluciones aceptadas (2)
1.169 Vistas
8 Respuestas
Respuestas (8)

CodeDing
Advisor
Advisor

@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

0 Me gusta

devitg
Advisor
Advisor

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

0 Me gusta

Kent1Cooper
Consultant
Consultant
Solución aceptada

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
0 Me gusta

devitg
Advisor
Advisor
Solución aceptada

@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 

 

 

0 Me gusta

jtohill
Advocate
Advocate

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

0 Me gusta

CodeDing
Advisor
Advisor

@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

0 Me gusta

ara_neresesian
Collaborator
Collaborator

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

 

 

 

0 Me gusta

Kent1Cooper
Consultant
Consultant

 


@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
0 Me gusta