[Search tip detail and code files using keywords, tip number, author name, etc ]
 
Manage Layers with Macros
Tip# 3240 By Perry Medina On 26-Jul-2009
1
Rated By 1 users
Categories : Layer States
Software type : AutoCAD 2010
Rename File To : No Files to download.
Program these macros into a button for a toolbar, tool pallet, or a button for the ribbon.

Perry Medina gives us a trick on managing layers with macros. Perry often uses large raster images in his drawing. This can slow things down when zooming and panning around a drawing.To speed things up, he turns them off and on as needed with a simple custom toolbar click or keyboard command. He uses "R-" to turn off all his raster images, and "R+" to turn them on.The trick is to place all your raster images on layers with "raster" as part of the layer name. Using the asterisk "*" wildcard in the macro before and after the word "raster", AutoCAD acts on any layer name with the word "raster" in it.

In toolbar macro, the code to turn layers with the name ‘raster’ off is: ^C^C_-layer;off;*raster*;;

To turn them back on use: ^C^C_-layer;on;*raster*;;

In a lisp routine, the code can be:

 
(DEFUN c:r- ()

    (setvar "cmdecho" 0)

    (command "layer" "off" "*raster*" "")

    (setvar "cmdecho" 1)

    (PRINC " All raster layers are now off. ")

    (princ)
)
________________________________________________________________
 
(DEFUN c:r+ ()
    (setvar "cmdecho" 0)

    (command "layer" "on" "*raster*" "")

    (setvar "cmdecho" 1)

    (PRINC " All raster layers are now on. ")

    (princ)
)
 

If used as a lisp routine you can load it into AutoCAD in the Acaddoc.lsp, or an appropriate ".mnl" file like this:

(load "r-") ; raster layers OFF

(load "r+") ; raster layers ON

This trick can be used with other layers too. For instance ^c^c_-layer;off;*|*;; in a toolbar macro will turn off all externally referenced layers since the vertical bar "|" is always part of the layer name. Using standardized layer names, only your imagination is the limit.

Notes from Cadalyst Tip Patrol: This is a great trick for using macros. You can program these macros into a button for a toolbar, tool pallete, or a button for the ribbon. Or, as Perry describes, create a LISP routine for them so you can use the keyboard to quickly change your layer states. 

 

Average Rating:
1


User comments