Jump to content
alanjt

LayerState Manipulation Info./Coding

Recommended Posts

alanjt

Thought it was about time I posted code. At least, more than just randomly posting in threads. Just finished this and seemed like a good starting point. I know it's mostly information about core commands, but I'm sure it's still valuable to some.

 

Information on how to manipulate/create/etc. LayerStates in code. Not sure when these were introduced, but they are working in 2009. I've also included a rewrite of the layerstate-save command to include the option to 'overwrite' LayerState, if already exists.

Enjoy. :)

;;; --------------------------------------------------[LayerStateInfo.lsp Begin]------------------------------------------------------------
;;; LayerState Manipulation Information and Subroutines
;;; ----------------------------------------------------------------------------------------------------------------------------------------
;;; Aside from 'AT:LayerStateSave', Alan J. Thompson claims NO ownership and NO responsibility for following coding. All are core AutoCAD.
;;; Compiled from: "AutoCAD 2009 Help: Developer Documentation"
;;; Tested and verified using AutoCAD Civil 3D 2009
;;; Compiled by: Alan J. Thompson, 09.09.09
;;; ----------------------------------------------------------------------------------------------------------------------------------------
;;; LayerState Values
;;; Combine numeric values to use more than one
;;; Example: (apply '+ '(1 2 4 8 16 32 64 128)) => 255
;;; ----------------------------------------------------------------------------------------------------------------------------------------
;;; Mask: An integer sum designating which properties in the layer state are to be restored.
;;; 1- Restore the saved On or Off value
;;; 2- Restore the saved Frozen or Thawed value
;;; 4- Restore the saved Lock value
;;; 8- Restore the saved Plot or No Plot value
;;; 16- Restore the saved VPVSDFLT value
;;; 32- Restore the saved Color
;;; 64- Restore the saved LineType
;;; 128- Restore the saved LineWeight
;;; 255- Restore everything
;;; ----------------------------------------------------------------------------------------------------------------------------------------
;;; Restore Flags
;;; ----------------------------------------------------------------------------------------------------------------------------------------
;;; Optional integer sum affecting how the layer state is restored.
;;; 1- Turn off all layers not in the restored layer state
;;; 2- Freeze all layers not in the restored layer state
;;; 4- Restore the layer state properties as viewport overrides (requires viewport to be not a nil value).
;;; ----------------------------------------------------------------------------------------------------------------------------------------
;;; Commands (Return T if successful, nil if not):
;;; ----------------------------------------------------------------------------------------------------------------------------------------
;;; Most useful, with information
;;; ----------------------------------------------------------------------------------
;;; LayerStateDelete        (layerstate-delete "LayerStateName")
;;; LayerStateList        (layerstate-getnames "T to include hidden layerstates, Optional" "T to include xref layerstates, Optional")
;;; LayerStateRename        (layerstate-rename "OldName" "NewName")
;;; LayerStateImport        (layerstate-import "Filename.las & path")
;;;                              Example: (layerstate-import c:\\mylayerstate.las)
;;; LayerStateExport        (layerstate-export "LayerStateName" "Filename.las & path")
;;;                              Example: (layerstate-export "Storm" "c:\\Storm.las")
;;; LayerStateRestore        (layerstate-restore "LayerStateName" "Viewport ename, nil for ModelSpace" "RestoreFlags <- See above list")
;;; LayerStateImportFromDWG    (layerstate-importfromdb "LayerStateName" "Filename.dwg & path")
;;;                              Example: (layerstate-importfromdb "Storm" "c:\\Storm.dwg")
;;; ----------------------------------------------------------------------------------------------------------------------------------------
;;; All LayerState-* Commands (Refer to AutoCAD 20XX Help: Developer Documentation for additional info.)
;;; ----------------------------------------------------------------------------------------------------------------------------------------
;;; layerstate-addlayers    Adds or updates a series of layers to a layer state
;;; layerstate-compare        Compares a layerstate to the layers in the current drawing
;;; layerstate-delete        Deletes a layer state
;;; layerstate-export        Exports a layer state to a specified file
;;; layerstate-getlastrestored    Returns the name of the last restored layer state in the current drawing
;;; layerstate-getlayers    Returns the layers saved in a layer state
;;; layerstate-getnames        Returns a list of the layer state names
;;; layerstate-has        Checks if a layer state is present
;;; layerstate-import        Imports a layer state from a specified 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 into the current drawing
;;; layerstate-save        Saves a layer state in the current drawing
;;; ----------------------------------------------------------------------------------------------------------------------------------------
;;; Rewrite of layerstate-save to include option to overwrite existing
;;; ----------------------------------------------------------------------------------------------------------------------------------------
;;; AT:LayerStateSave (Option to overwrite)
;;; #Name - LayerState name
;;; #Mask - Numeric value for restoring options (see above list)
;;; #ViewportID - Ename (ads_name) of the viewport to which layerstatename should be restored.
;;;               If viewport is nil, the layer state is restored to model space.
;;; Alan J. Thompson, 09.09.09
(defun AT:LayerStateSave (#Name #Mask #ViewportID #Overwrite)
 (and #Overwrite
      (layerstate-has #Name)
      (layerstate-delete #Name)
 ) ;_ and
 (layerstate-save #Name #Mask #ViewportID)
) ;_ defun
;;; ----------------------------------------------------[LayerStateInfo.lsp End]------------------------------------------------------------

Share this post


Link to post
Share on other sites

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.
Note: Your post will require moderator approval before it will be visible.

Guest
Reply to this topic...

×   Pasted as rich text.   Paste as plain text instead

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.


×
×
  • Create New...