How to change text style from VBA code

How to change text style from VBA code

Anonymous
Not applicable
5,097 Views
5 Replies
Message 1 of 6

How to change text style from VBA code

Anonymous
Not applicable

Hi all,

 

I am writing a vba code which opens the CAD and insert titleblocks. Next, I want to edit the blocks and insert text from excel for example drawing name, etc. 

So far, I am able to do all of this, but I also need to change the text style of each inserted text one by one right after inserting them into the drawing.

Does anyone have any idea for this?

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

Ed__Jobe
Mentor
Mentor
Accepted solution

Added text is created using the current defaults. You can change the current style before you add any text using

ThisDrawing.SetVariable "TEXTSTYLE", "someStyleName"

 

When you change vars like this, its courteous to save the current setting and reset it when you're done. Use GetVariable to get the current value.

Ed


Did you find this post helpful? Feel free to Like this post.
Did your question get successfully answered? Then click on the ACCEPT SOLUTION button.
How to post your code.

EESignature

0 Likes
Message 3 of 6

Anonymous
Not applicable

Thanks Ed. I could make it work. Do you also know how I can change other features such as:

Text width, Position X,Y, Z (not text alignment X Y Z), text alignment (top center,etc.)?


@Ed__Jobewrote:

Added text is created using the current defaults. You can change the current style before you add any text using

ThisDrawing.SetVariable "TEXTSTYLE", "someStyleName"

 

When you change vars like this, its courteous to save the current setting and reset it when you're done. Use GetVariable to get the current value.



@Ed__Jobewrote:

Added text is created using the current defaults. You can change the current style before you add any text using

ThisDrawing.SetVariable "TEXTSTYLE", "someStyleName"

 

When you change vars like this, its courteous to save the current setting and reset it when you're done. Use GetVariable to get the current value.


 

0 Likes
Message 4 of 6

Ed__Jobe
Mentor
Mentor

The other way you could do it is modify the text just after you insert it.

 

Dim oText As AcadText

oText = ThisDrawing.Modelspace.AddText

With oText

   .Style = "someName"

   .Height = .125

   .Alignment = acAlignmentLeft

End With

Ed


Did you find this post helpful? Feel free to Like this post.
Did your question get successfully answered? Then click on the ACCEPT SOLUTION button.
How to post your code.

EESignature

0 Likes
Message 5 of 6

omar.villalobos
Contributor
Contributor

Buenos días, le saluda Omar Villalobos.

Buscando solución a un problema me encontré con la misma duda del tema en cuestión.

el asunto es que al parecer ya esta resuelto por las respuestas que he visto, pero el problema es que no entendí bien (no veo donde escribir el nombre de la Fuente).

 

¿Podría crear la macro con la opción especifica de crear el texto con su debido estilo de Fuente?

 

Osea que ejecutado la Macro VBA me cree en AutoCad el Nuevo estilo de texto llamado "Nuevo", utilizando la Fuente de texto "Arial Narrow" y que utilice dicho estilo escribiendo una palabra en la pantalla. 

Por favor. Gracias.

 

0 Likes
Message 6 of 6

israel_veliz_89
Observer
Observer

Buenas, he visto la pregunta inicial y tengo una duda. He probado cambiar el estilo de texto en autocad. Pero, mi estilo de texto es anotativo y veo q autocad no le asigna esa propiedad. Saben como puedo solucionarlo?

 

0 Likes