CAD-e-Corner
5th Sep 2006, 09:14 pm
Scripts are used to automate repetitive tasks in AutoCAD. A good example for this would be modifying layer settings.
If you can type it, you can Script it. This means that you'll need to become familiar with the command line versions of several AutoCAD commands. To run the command line version of a dialog driven command, like LAYER, you prefix the command with a dash: -LAYER
So here's a typical scenario: You attach an architectural floor plan background to your drawing. Now you want to set all or some of the layers to a screened Color or Plot Style. You also want to Freeze all the architectural background Layers except those germane to your discipline. If the architect later adds a Layer to their background, and it now inconveniently shows up in your drawing, you can simply rerun the Script to Freeze it, restoring your drawing to the desired display state.
Use Notepad (or your favorite text editor) to create the Script ALAY.SCR; it must have the extension .SCR to be recognized as an AutoCAD Script. Enter the following lines (or similar):
LAYER C 51
*|A-*
C 2
*|A-AREA-IDEN
F
*|A-*
T
*|A-AREA-IDEN*,*|A-DOOR-*,*|A-WALL-FULL*,etc.
Let's look at the Script line by line.
Line 1 executes the Layer command, specifies the Color option and selects Color 51.
Line 2 uses wildcards to apply Color 51 to all Layers that are both Xref dependent (includes a "|") and start with A-.
Lines 3 and 4 similarly reset the Room Number Layer to Color 2.
Lines 5 and 6 Freeze all Xref Layers that begin with A-.
The last two lines then Thaw all the Layers we want to display in our background, using wildcards where appropriate.Some notes on our script:
Execute the Script by typing SCRIPT and selecting ALAY.SCR from the Open dialog, or drag-and-drop the Script from Explorer, or put the Script on a Tool Palette.
Notice that I didn't use -LAYER in the script; AutoCAD is smart enough to use the command line version of commands when called from a Script.
Wildcards can be asterisks or question marks. Asterisks match multiple characters and question marks match a single character.
Spaces act as enters in Scripts (similar to how they do at the command line), except where AutoCAD expects text entry then spaces are allowed (as in Layer names). That's why our Layer name entries are all on separate lines.
The Layer command needs an additional Enter to exit the command, so be sure to include an extra blank line at the bottom of your Script.
More... (http://cadecorner.blogspot.com/2006/08/using-scripts-to-automate-layer.html)
If you can type it, you can Script it. This means that you'll need to become familiar with the command line versions of several AutoCAD commands. To run the command line version of a dialog driven command, like LAYER, you prefix the command with a dash: -LAYER
So here's a typical scenario: You attach an architectural floor plan background to your drawing. Now you want to set all or some of the layers to a screened Color or Plot Style. You also want to Freeze all the architectural background Layers except those germane to your discipline. If the architect later adds a Layer to their background, and it now inconveniently shows up in your drawing, you can simply rerun the Script to Freeze it, restoring your drawing to the desired display state.
Use Notepad (or your favorite text editor) to create the Script ALAY.SCR; it must have the extension .SCR to be recognized as an AutoCAD Script. Enter the following lines (or similar):
LAYER C 51
*|A-*
C 2
*|A-AREA-IDEN
F
*|A-*
T
*|A-AREA-IDEN*,*|A-DOOR-*,*|A-WALL-FULL*,etc.
Let's look at the Script line by line.
Line 1 executes the Layer command, specifies the Color option and selects Color 51.
Line 2 uses wildcards to apply Color 51 to all Layers that are both Xref dependent (includes a "|") and start with A-.
Lines 3 and 4 similarly reset the Room Number Layer to Color 2.
Lines 5 and 6 Freeze all Xref Layers that begin with A-.
The last two lines then Thaw all the Layers we want to display in our background, using wildcards where appropriate.Some notes on our script:
Execute the Script by typing SCRIPT and selecting ALAY.SCR from the Open dialog, or drag-and-drop the Script from Explorer, or put the Script on a Tool Palette.
Notice that I didn't use -LAYER in the script; AutoCAD is smart enough to use the command line version of commands when called from a Script.
Wildcards can be asterisks or question marks. Asterisks match multiple characters and question marks match a single character.
Spaces act as enters in Scripts (similar to how they do at the command line), except where AutoCAD expects text entry then spaces are allowed (as in Layer names). That's why our Layer name entries are all on separate lines.
The Layer command needs an additional Enter to exit the command, so be sure to include an extra blank line at the bottom of your Script.
More... (http://cadecorner.blogspot.com/2006/08/using-scripts-to-automate-layer.html)