Force Objects Properties to ByLayer. Post 4 in series “AutoCAD Cleanup”

In AutoCAD 2008, there is a new cleaning tool: SETBYLAYER (menu: Modify->Change to ByLayer). Before using this command in a script, let’s take a look at its settings. Select it from the menu or type SETBYLAYER from the command line, then type “s” to get to the setbylayer settings dialog box. Here you can easily select which properties will be changed. But dialog boxes cannot be used in scripts, so we will use the SETBYLAYERMODE variable to select the properties that we want to change.

setbylayer1The default value of the SETBYLAYERMODE variable is 127. It is NOT saved in the drawing. The picture on the left shows value corresponding to each property. In addition:
+32 Changes ByBlock to ByLayer
+64 Includes blocks when changing ByBlock to ByLayer

To select several properties, add these values. For example, to change just color and lineweight to ByLayer including all objects in blocks and ByBlock objects, set SETBYLAYERMODE=1+4+32+64=101.

The following script will change only color and lineweight of all objects (including set to ByBlock and nested in the blocks) on unlocked layers in modelspace and layout. Note that there are two spaces between “ALL” and first “Y” and one space between first and second “Y”

SETBYLAYERMODE 101
 TILEMODE 1
 SETBYLAYER ALL Y Y
 TILEMODE 0
 SETBYLAYER ALL Y Y
 QSAVE
 Blank Line