Categories

AutoCAD 2015 and AutoCAD LT 2015 Bible

The most comprehensive AutoCAD book around!

Change the font of a text style using AutoLISP

This is a guest post by Sanjay Kulkarni, an AutoCAD programmer. You can read more about him at the end of this post.

In the current era of globalization, many times you may have to work on drawings received from others. Sometimes, you may not be able to control the quality of the drawings you receive. In such a situation, you may have to carry out a repair job on the drawings. Such tasks can be made less tedious if you standardize these tasks and carry them out using AutoLISP.

One of my Indian clients receives drawings from their European principals. One of the repair jobs is to change the font of the text inside dimensions, attributes, tables & notes. Since all these texts are included inside their respective block, the task becomes more complicated than is really necessary.

Most of the text, however, is controlled by the text style. Thus, the job is really to change the font in the text style. But there are a handful of the text styles. So, it becomes a time consuming task.

I helped them with a simple AutoLISP function that made this job virtually painless. The function changes the association of a text style from existing font file to another font file. The function takes 2 parameters, the name of the existing text style and the name of the font file that will be associated with the text style.

You can download the function here.

How to use the AutoLISP function

This function can be used like this:

(chngFontOfTxtStyle “<TextStyleName>” “<DifferentFont.xtn>”)

As you may have noticed, this function can be used only inside another AutoLISP program. This calling AutoLISP program can provide the user interface that you may need. Following are a couple of sample situations that you can build around this function.

1. Ask the user to type the names of the text style and font file and store them in variables. Call the above function with these two variables as parameters.

2. Ask the user to type the name of the font file. Browse programmatically through all the text styles and repeatedly call the above function with name of each text style and name of the font file as parameters. This will change the font of all text styles.

As you can see, there is no limit to the situations you can build and keep using the function.

For example, you could enter the following on the command line:

(chngFontOfTxtStyle “Something Funny” “arial.ttf”)

In this case, the name of the text style is Something Funny and you want to change the font to Arial.

How to get help for the function

Also note that this function has built in help. The message is displayed as soon as you load the lisp file to type cfot? (note the use of ? to indicate help) at the command prompt. If you type this, minimal help is displayed at the command prompt.

How do you know that the font name association was successfully changed? As described in help, the function returns 0 if successful or -1 if not. You will need to check the return value.

What other tasks do you want to automate?

Are you stuck-up with such trivial tasks that are strain on your resources. Let me know directly (my email is below) and we’ll see if I can help you with useful hints or sample code. Or you can post a comment.

Sanjay Kulkarni is an experienced CAD (AutoCAD, Inventor, SolidEdge, CATIA, NX) programmer and a member of the Autodesk Developer Network. He is fluent in AutoLISP, VBA, and VB.NET. He has written for AugiWORLD and Inside AutoCAD (a monthly magazine that has since gone out of publication). He can be contacted at sanganaksakha@gmail.com

 

Ellen Finkelstein

17 comments to Change the font of a text style using AutoLISP

  • tommybluegrass

    No lisp publish on web page. At least I could not find it.

  • Ellen

    Yes, it’s hard to find. Hover the cursor over the end of the sentence that says, “You can download the function here” and you’ll see the link.

  • Steven

    How can i activate the lsp-function in acad?

  • Ellen

    Do you mean load an AutoLISP program?
    See if this helps: https://allaboutcad.com/how-to-load-an-autolisp-program/

  • upali

    i need to identify current text style, whether vertical style or normal style in lisp programming

  • Peter Parker

    It works!!!! Thanks!!

  • Robert

    I have a large library and I recently bought a refurbished computer with Vista Ultimate> I loaded my 2009 Cad and looked at my drawings and all of the Fonts changes which messed up all of the drawing and details. Everything elese seems fine and when I change them to arial it gets very close but not quite right and some I have to move around to fit back into place. Is there a setting or funtion I am not seeing, I really do not want to fix over 1600 projects and thousands of details. any help would be greatly appreciated!!

  • Ellen

    Hmmm, I haven’t heard of that. When you edit text, which font does it say it’s using?

  • James

    I was trying to put a logo into a title block, for a student exercise, using a wider font. But the rest of the words in the title block always change over to the logo font. Is there a way to add a logo?

  • Ellen

    You could insert it as an image. But you should be able to have 2 different fonts in separate areas, just as you can anywhere in a drawing.

  • Luis

    Hi,

    Command: (chngFontOfTxtStyle “dgn020” “Style-Font 20.shx”)
    ; error: too many arguments

    Any idea?

    thanks!!

  • edpher

    i’m having a problem with my fontstyle. yesterday i used Romans but today i opened was shocked looking at my working drawing call-outs because they are now in Arial Black.. need help on how can i return all my texts back to Romans in a simple remedy or without editing each call-out by entering the mtext window because it takes a lot of time revising all the call-outs.. i hope you can assist me regarding this.. Thank you.

  • Hans Graveman

    Edpher

    Use the STYLE command and look for Romans and see if the fontname is Romans and fontstyle is standard

    Hans Graveman

  • gopal

    see i also want to change the width factor.. what shall i do ? i tried sm lisp prograames bt it only change the style (inlcuding font) bt ddint work with width factor. plz guide

  • Hans Graveman

    Ellen all the links are corrupted my virus scanners warns not to go there

  • Dave

    I tried using this lips in AutoCAD 2015, but the changes to the text style does not look to be saved in the file, when I re-open the file, the fonts in the text styles that the lisp changed get reverted back to the original font. Please help, this lisp is great if I can get it to save.

  • Quoc Son Duong

    hi ellen i just dowloaded chngFontOfTxtStyle and add it into autocad, but don’t know how to use this autolisp, type command…. to change all style to romands standard, i need to help baddly, can you help me, thanks a lot, if you have clip to direct is better

Leave a Reply

You can use these HTML tags

<a href="" title=""> <abbr title=""> <acronym title=""> <b> <blockquote cite=""> <cite> <code> <del datetime=""> <em> <i> <q cite=""> <s> <strike> <strong>