AutoCAD Scripts are a great way to manage Layers in AutoCAD. Since layer commands like Merge and ReName can be controlled through command line entry and Layer Properties can also be modified through text-based commands and entries, scripts can streamline and automate the repetitive processes for working with multiple layers.
In this post, I’ll share some tips on setting up a spreadsheet for some easy layer scripts and linking cells to populate layer properties with existing layer data from AutoCAD.
The base spreadsheet contains a reference tab that will be used for pasting the layer information from AutoCAD directly into the file. The additional tabs are set up for customized scripts that run through the ReName and Merge Layer commands. To keep things organized, the tab names are associated with what they contain.
The first tab is named Paste Layer INFO and is used for exactly that. From the AutoCAD Layer Properties Manager, you can Select All (CTRL+A) then Copy (CTRL+C) and Paste (CTRL+P) the content from AutoCAD into the spreadsheet. Setting up some Layer Filters to create subsets of layers that you prefer to work with is also a great idea to speed things up when copying and pasting out of AutoCAD. The reason these cells are linked to other tabs is because the Copy/Paste commands will copy all of the content and properties out of the Layer Properties Manager, including column headings and all properties within the panel.
Based on the layout of the data pasted into the spreadsheet, cell B4 (skipping Layer 0) will be the first cell that contains relevant information for the AutoCAD scripts we’re creating
The first script tab is called Layer ReNamer and is used for renaming multiple layers at once. For this tab, the -LAYER command is our “root” command for the script with the “R” for ReName option. This command is repeated as many times as needed to rename all of the relevant layers from the existing AutoCAD file.
The script itself contains both linked and manually entered data. Color coded formatting is used to indicate Linked Cells in Column B and User Input cells in Column C. The first linked cell in this tab (B4) is referenced back to the pasted content (=’Paste Layer INFO’!B4). The cells below are auto-filled as needed to populate the rest of the column from the pasted data. Column C is the new name for the layer that is manually entered by the user.
Exporting this to a .TXT and converting to .SCR creates a script that automatically renames all layers in Column B to the new names entered into Column C.
The Layer MERGE tab is similar, but includes some additional content and columns that are specific to the -LAYMRG command. Once again, the existing layer names are linked back to the Paste Layer INFO tab cells, and the remaining content is manually entered. The auto-fill function comes in handy here to fill in the intermediate columns containing command options.
Since the Layer Merge command includes two sets of existing layers, the Layer Name to Merge With column can also be linked back to data that is copied and pasted from AutoCAD. Using a Layer Filter to sort the layers before using Copy/Paste will make that process quicker and easier. Having a secondary reference tab for the Layer Names to Merge With also helps keep things organized within the spreadsheet.
For this script, the Layers in Column B will be Merged into the Layers named in Column E automatically when the script is run in AutoCAD and all of the confirmation prompts will be answered without any additional user input.
Linking pasted data and auto-filling cell content are just a couple of ways you can leverage spreadsheet functionality for generating AutoCAD Scripts. Since the script tabs are linked back to copied and pasted content, they can be updated quickly by copying and pasting new data from other AutoCAD files. The linked cells update as soon as the new data is pasted, and auto-fill populates as many cells as you need to accommodate the new layers.
Once the data is in the spreadsheet, having everything organized in columns and rows provides a nice visual arrangement of the script data and exporting to .TXT is a quick option for generating script (.SCR) files directly from the spreadsheet.
About the AuthorFollow on Linkedin More Content by Matt Miyamoto