One of the features not included in the new AutoCAD 2011 for Mac release is the Layer States Manager dialog. This dialog gives you visual access to all your basic layer state operations as well as more advanced stuff such as editing the properties of layers within saved layer states. The fact that running the LAYERSTATE command returns "unknown command" might lead you to believe that layer state-based management is dead on the Mac. Not so.
Although the Layer State Manager dialog is not available in AutoCAD for Mac, most of the really important layer state operations can still be performed using either the -LAYER command or the (layerstate-xxx) AutoLISP functions.
Using the stAte option of the -LAYER command, you can do the basics like saving, restoring and deleting layer states. Using the different (layerstate-xxx) AutoLISP functions, you can do quite a bit more. Here is a list of the available functions:
(layerstate-addlayers)
Adds/updates a series of layers to a layer state
(layerstate-compare)
Compares a layer state to the layers in the current drawing
(layerstate-delete)
Deletes a layer state
(layerstate-export)
Exports a layer state to an .LAS file
(layerstate-getlastrestored)
Returns the name of the last restored layer state in the current drawing
(layerstate-getlayers)
Returns a list of the layers saved in a layer state
(layerstate-getnames)
Returns a list of the layer state names in the drawing
(layerstate-has)
Checks if a layer state is present in the drawing
(layerstate-import)
Imports a layer state from a specified .LAS file
(layerstate-importfromdb)
Imports a layer state from a specified drawing file
(layerstate-removelayers)
Removes a list of layers from a layer state
(layerstate-rename)
Renames a layer state
(layerstate-restore)
Restores a layer state in the current drawing
(layerstate-save)
Saves a layer state in the current drawing
These AutoLISP functions will cover the vast majority of the functionality you could get from using the Layer State Manager dialog. Check your AutoCAD help for specific usage details. It looks like the AutoCAD for Mac online docs don't include a reference to AutoLISP functions but you can check the AutoCAD 2011 docs here:
If you're restoring layer states to viewports, you'll want to refer to the following post from earlier this year that explains some limitations with the -LAYER command that can be overcome using the (layerstate-restore) function:
Restoring Layer States with -LAYER
That posting explains how to use the (layerstate-restore) function in conjunction with an Express Tools function that returns the entity ID of the current viewport, e.g.,
(layerstate-restore "mylayerstate" (acet-currentviewport-ename))
Since AutoCAD for Mac does not include the Express Tools you'll want to use a function like the following to get the viewport entity ID and then pass it to the (layerstate-restore) function:
(defun cvport-ename (/ ssvp vpe)
(setq ssvp (ssget "_x"
(list '(0 . "VIEWPORT")
'(67 . 1)
(cons 69 (getvar "cvport"))
(cons 410 (getvar "ctab"))
)))
(if ssvp
(setq vpe (ssname ssvp 0))
)
vpe
)
(layerstate-restore "mylayerstate" (cvport-ename))
Note: This function is pretty basic and will likely fail on layout names that include wildcard characters. You are welcome to add the additional layers of error checking and string replacement on your own. Plan accordingly.
Thus, with a few minor exceptions, you can still handle most of the really important layer state operations even though you don't have the Layer State Manager dialog.
Comments