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.
Did you find this tip helpful?
Don't miss new tips!
Plus get a free Dynamic Blocks tutorial
Enter your name and email below
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 [email protected]