Have you used publish in AutoCAD to create single sheet PDF? AutoCAD will create the file name automatically.
AutoCAD will publish the PDFs by using the layout name. The only option you have is to add file name as prefix. There is no option to create PDFs using file name only.
Now what if you want to have multiple PDF files that use file name? You can’t.
What you can do is to publish them with format file name and layout name, then rename them. Hai Le shares how this can be done quickly and easily. You can use MS-DOS command “rename” using wildcards.
It has limitation, but if your PDF file name follow a pattern like image above, then you can use this method.
This is not really an AutoCAD tips. We will use command prompt and don’t touch AutoCAD at all.
Working with command prompt
Many people today don’t work with command prompt anymore. So let’s start with some introduction.
To open command prompt
To open command prompt, hold win key + R. Win key is the one on your keyboard with Windows logo.
This will open run window. Type CMD then press enter.
Now you have command prompt window open. In this window, you can type old school MS-DOS commands like copy, delete or rename.
First thing you need to do is to change the active folder to your PDF location.
You can use CD to change folder (CD stands for change directory. Before Windows, we call it directory instead of folder).
If I want to open c:\data then I can use cd c:\data. You can see the prompt changed to new active folder.
Understanding the wildcards
Before we start to rename the files, let’s try to understand about wildcards first. You need to understand the file name pattern before you can rename your files.
The command to rename file is
rename ORIGINALNAME NEWNAME
Rename A.PDF B.PDF will rename file A.PDF to B.PDF.
But in this case, we want to rename multiple files at once. So we need to use wildcards. We can use wildcards * or ? for this purpose.
To get all file name with a defined name length
If we use ? then it will accept any alphanumeric character.
????.PDF will accept all PDF files that have name with 4 characters long:
To get all file name with undefined name length
The * wildcard will accept all characters regardless how many character they have.
*-Layout1.PDF will accept all files that end with –Layout1.PDF
- Floor Plan-Layout1.PDF
*-Layout*.PDF will accept all files that has –Layout in the file name, with PDF as file extension.
- Floor Plan-Layout1.PDF
- Site Plan-Layout2.PDF
Using rename command
Now that we understand how to use wildcards, let’s see how to use rename command with wildcards.
Now let’s see how we can use wildcards when renaming the files.
The command above will try to find all PDF files, then rename them. It keeps only first 4 characters, ignore the file name after 4th character.
We have a small problem. In this example you can see AS-01-Layout01.PDF is renamed to AS-0.PDF. We want the result to be AS-01, not AS-0. We need the result as 5 characters for this particular file.
We need to make a better file name pattern. Let’s try again.
This command will rename the files as follows
As you can see, the AS-01 was not renamed. You can use rename command again here if you have many files like this. If there’s only one, you can also rename it from File Explorer.
Creating a batch file
If you need to do this regularly, it’s a good idea to create a batch file. Especially if you have multiple file pattern.
You can create a batch file using notepad. Type each command in separate lines like below.
This batch file will run the rename command twice, for 2 different file name pattern.
After you created it, save it with .bat as file extension. When you save from notepad, use double quote (“) like below.
When you need to rename files in a folder, just copy this batch file to the folder. Double click to execute the commands.
Not every problem can be solved from within AutoCAD. Sometimes we need to improve and use other tools. Command prompt and batch file is a great tool, and knowing them will help.
Do you have any other command prompt and batch file experience that you can share with fellow CAD users? Share them here!
Special thanks to Hai Le for the great tip!