Updating block is a common issue that AutoCAD users have. Sometimes we need to update a block definition, and sometimes we need to do on multiple files at once. The frequent question I see is how to update title block in multiple files with a new definition. Using a block as the title block is a common practice because we can reserve the text field with attributes. The downside of using a block is when we need to update it. We need to update it on each file.
In this article, we will cover how you can use an AutoCAD script and run it with ScriptPro. We covered ScriptPro before; it might be better if you read it first.
Preparing the block
Before we start, we need to create the block in a separate file. You need to explode the block, then save it as an external file with WBLOCK command.
Save it with the same name as the block. If you want to update block named “title”, then save it as title.dwg.
Save the file in a folder. In this article, we use D:\Data as the example. It’s important to use a specific folder for this purpose and not mixing it with other files. Because we will add this folder in Working Support File Search Path.
Open AutoCAD options. In Files tab, under Working Support File Search Path add the block folder.
You can place your blocks in this folder. When you need to update a particular block, AutoCAD will search in this folder.
Creating the Script
Now let’s create the script. Open text editor application such as Notepad.
Updating a block definition is simple. We insert a block with the same name, and AutoCAD will update the definition after we confirm it.
The script will be like this:
-INSERT title= (COMMAND \E "RESUME") QSAVE
Type the command in the notepad and save the file as “blockupdate.scr”.
Include the double quote to force Windows saving it in the .scr file extension.
The script explained
- -INSERT is the command to insert a block definition. The – character is to suppress the dialog box. Because we want to run a sequence of command, we need to run it without a dialog box.
- title= is the block name. Title is the actual block name. You need to add = to allow AutoCAD update the block from an external file. Replace the block name with yours and don’t forget to add =
- (COMMAND \E “RESUME”) is the AutoLISP command to replace Esc key. AutoCAD still asks to define the insert point, scale, and rotation angle. We do not insert another block instance to the drawing, so we can just cancel it. However, after INSERT command we still need AutoCAD to do another command. So we add RESUME after the Esc.
- QSAVE is to save the drawing file. Remember that ScriptPro doesn’t save the file, we need to define it in the script. Don’t forget to add an empty line below QSAVE.
If you use AutoCAD LT
AutoCAD LT can’t execute AutoLISP command. Therefore you can’t use (COMMAND \E) to simulate the Esc key. So you can just add the block and erase it immediately after you place it.
You can use this script as an alternative.
-INSERT title= 0 1 1 0 Erase Last QSAVE
The script will place the block at 0,0,0 with scale 1, rotation 0. Then erase the last object created.
A new line in the script is the same as pressing Enter key once. That’s why we add an empty line after Last. We need to press Enter twice.
Test the script
After you created the script, it is important to try it first. Make sure it works before you run it on dozens of drawings. Check the command line after you execute the script and see if there’s something wrong.
I tried this script on AutoCAD 2018 and AutoCAD LT 2018. You might see different behavior in a different version.
Running the Script with ScriptPro
After you are sure the script is running as expected, now you can run it on multiple drawings. It’s always a good idea to create a backup before we start. Copy the drawing file before you run the script.
We already cover how to run a script on multiple drawings, so you need to open this article to continue: Run a script on multiple DWG with ScriptPro.
Running the Script Even Faster
Garry Nelson gave me an interesting information about AutoCAD Core Console, the accoreconsole.exe.
Using ScriptPro to do a batch process on multiple drawings is very helpful. But as we run it automatically, we don’t need to see the UI. And we don’t even need to see the file when the process run. You can use AutoCAD Core Console to run it much faster; it’s faster than I thought. It runs the process without an interface, without opening the file. It simply runs with the command line.
To use AutoCAD Core Console, you need to change the ScriptPro options. In the AutoCAD application to use, set the application to accoreconsole.exe. The file is in the same folder as AutoCAD. Usually in C:\Program Files\Autodesk\AutoCAD 201x\
If you want to read more about AutoCAD Core Console, visit Through the Interface blog: The AutoCAD 2013 Core Console.
Thank you, Garry, for the cool tip!
What else can you do with ScriptPro?
ScriptPro is very useful tool, and if you can use it right, it can look like black magic. With AutoCAD Core Console, it literally can save very significant time.
Now if you are already usingScriptPro, what do you use it? If you haven’t used it, do you have a plan how you are going to use it?