How do I script LAYER operations in batch?


Three layer jobs come up again and again on the forum, and all three are scriptable through Hurricane: clearing junk layer filters, selecting everything on one layer, and setting layer states (on/off/freeze/lock) across many drawings.

Set layer states with -LAYER

-LAYER is the no-dialog version of the Layer command. Its options cover everything a script needs: Make, Set, New, On, OFf, Freeze, Thaw, LOck, Unlock, COlor, and more. For example, to freeze a layer and turn another off:

-LAYER
;Freeze a layer (wildcards allowed, e.g. XREF*)
F
DEFPOINTS
;Turn off every layer starting with DIM
OFF
DIM*
;The next line is intentionally blank: it exits the command

Keep comments on their own lines, starting with a semicolon. A comment after a value on the same line is sent to AutoCAD as part of the value (see How do I add comments to my scripts?).

Delete ALL layer filters (without stalling the script)

Inherited drawings often carry dozens of nested layer filters that clutter the Layer Manager. The catch: most "delete filters" routines prompt, and a prompt stalls an unattended batch. The Hurricane forum hosts a no-prompt version that just removes them all:

Get the routine: delfiltersall.lsp from Delete all Layer Filters on the Hurricane Forum, a script-safe build that deletes every layer filter with no questions asked.

Select all objects on a specific layer

There's no native command-line "select by layer", but the classic SSX (Selection Set by example) routine does it, and is handy inside scripts. The forum has a copy since Autodesk dropped it after R14:

Get the routine: SSX.zip from Selecting by layer in a script (SSX). A no-LISP workaround also works: -LAYER Lock every layer except the target, then SELECT ALL. Locked layers are skipped.
💬 From the Hurricane Forum: Delete all Layer Filters (script-safe) · Select objects by layer in a script (SSX) · Import / create layers from a text file

Related

Check first with Tornado: Tornado DWG Scanner's Layer states check counts the frozen, off and locked layers, and its Non-standard layers check lists layers that are not on your company list, for every drawing in a folder, in one spreadsheet.

PreviousBack to Hurricane for Autodesk® AutoCAD® - FAQNext