onzki Posted July 9, 2010 Posted July 9, 2010 I find layer state very useful. However, info from ACAD's Help concerning it was very limited. To access a layer state, I always need to pass at the usual Layer properties.. and click some icons. Is it possible to have an LISP or shortcut that will enable me to easily recall/restore a specific saved layer state? Say a command like RL1 (restores my layer state named as 1) and so on.. or similar scenario. Thanks a lot! Quote
Lt Dan's legs Posted July 9, 2010 Posted July 9, 2010 you mean toggle the layer on or off? If so http://www.cadtutor.net/forum/showthread.php?t=45943 or look at: http://www.theswamp.org/index.php?topic=33764.msg391362#msg391362 Quote
Lee Mac Posted July 9, 2010 Posted July 9, 2010 I don't use layerstates, but: (defun c:rl1 nil (vl-load-com) (layerstate-restore "1" nil nil) (princ) ) Read the help files on the layerstate functions, I'm sure you could get somewhere. Quote
onzki Posted July 12, 2010 Author Posted July 12, 2010 Thanks for the reply and code, more power to you guys! @Lee Mac: Thanks, but I think there's a problem with my CAD- an error message "no function definition" (see attached). I'm using 2007 version. What do you think? Uploaded with ImageShack.us Quote
alanjt Posted July 12, 2010 Posted July 12, 2010 The LayerState functions weren't introduced until '09, I think. Quote
alanjt Posted July 12, 2010 Posted July 12, 2010 I was thinking I had some of these functions in my archive folder... ;;; Alan J. Thompson ;;; LayerStateSave Values ;;; Combine numeric values to use more than one (ie: 32+2+64) ;;; CONSTANT LAYER PROPERTY NUMERIC VALUE ;;; ----------------------------------------------------- ;;; acLsAll All 65535 ;;; acLsColor Color 32 ;;; acLsFrozen Frozen or thawed 2 ;;; acLsLineType Linetype 64 ;;; acLsLineWeight Lineweight 128 ;;; acLsLocked Locked or unlocked 4 ;;; acLsNewViewport New viewport layers 16 ;;; frozen or thawed ;;; acLsNone None 0 ;;; acLsOn On or off 1 ;;; acLsPlot Plotting on or off 8 ;;; acLsPlotStyle Plot style 256 ;;; LayerStateList (defun LayerStateList (/ #List) (vlax-for x (vla-item (vla-getextensiondictionary (vla-get-layers (vla-get-activedocument (vlax-get-acad-object)) ) ;_ vla-get-layers ) ;_ vla-getextensiondictionary "ACAD_LAYERSTATES" ) ;_ vla-item (setq #List (cons (vla-get-name x) #List)) ) ;_ vlax-for (reverse #List) ) ;_ defun ;;; LayerStateManager (defun LayerStateManager (/) (or *LayerStateManager* (setq *LayerStateManager* (vla-getinterfaceobject (vlax-get-acad-object) (strcat "AutoCAD.AcadLayerStateManager." (itoa (fix (atof (getvar "acadver")))) ) ;_ strcat ) ;_ vla-getinterfaceobject ) ;_ setq ) ;_ or (vla-setdatabase *LayerStateManager* (vla-get-database (vla-get-activedocument (vlax-get-acad-object)) ) ;_ vla-get-database ) ;_ vla-setdatabase ) ;_ defun ;;; LayerStateRelease (defun LayerStateRelease (/) (not (vl-catch-all-error-p (vl-catch-all-apply 'vlax-release-object (list *LayerStateManager*) ) ;_ vl-catch-all-apply ) ;_ vl-catch-all-error-p ) ;_ not ) ;_ defun ;;; LayerStateSave (defun LayerStateSave (#Name #Prop) (LayerStateManager) (if (not (vl-catch-all-error-p (vl-catch-all-apply '(lambda () (vlax-invoke-method *LayerStateManager* 'Save #Name #Prop) ) ;_ lambda ) ;_ vl-catch-all-apply ) ;_ vl-catch-all-error-p ) ;_ not #Name ) ;_ if ) ;_ defun ;;; LayerStateRestore (defun LayerStateRestore (#Name) (LayerStateManager) (if (not (vl-catch-all-error-p (vl-catch-all-apply '(lambda () (vlax-invoke-method *LayerStateManager* 'Restore #Name) ) ;_ lambda ) ;_ vl-catch-all-apply ) ;_ vl-catch-all-error-p ) ;_ not #Name ) ;_ if ) ;_ defun ;;; LayerStateDelete (defun LayerStateDelete (#Name) (LayerStateManager) (if (not (vl-catch-all-error-p (vl-catch-all-apply '(lambda () (vlax-invoke-method *LayerStateManager* 'Delete #Name) ) ;_ lambda ) ;_ vl-catch-all-apply ) ;_ vl-catch-all-error-p ) ;_ not #Name ) ;_ if ) ;_ defun Quote
onzki Posted July 13, 2010 Author Posted July 13, 2010 The LayerState functions weren't introduced until '09, I think. I see, maybe that's why it isn't working on my current version. Thanks! Quote
alanjt Posted July 13, 2010 Posted July 13, 2010 I see, maybe that's why it isn't working on my current version. Thanks! You're welcome. Try the above routines. I put those together while still running an older version of Acad. Quote
onzki Posted July 14, 2010 Author Posted July 14, 2010 You're welcome. Try the above routines. . Thanks Alan, I'm a newbie sorry to ask but how will I use it, I mean what should I be typing at command line? are the words after "defun" means command? Thanks! Quote
Lee Mac Posted July 14, 2010 Posted July 14, 2010 The functions Alan has kindly posted are 'subfunctions' or 'library functions' - these are not designed to be called straight from the command line but rather called from a program. Some will also take arguments (as is sometimes noted in code headers) - you will need to make sure that you supply the function with the correct number of arguments and argument type for the function to work correctly. Quote
onzki Posted July 14, 2010 Author Posted July 14, 2010 The functions Alan has kindly posted are 'subfunctions' or 'library functions' - these are not designed to be called straight from the command line but rather called from a program. Some will also take arguments (as is sometimes noted in code headers) - you will need to make sure that you supply the function with the correct number of arguments and argument type for the function to work correctly. I see, thanks for the info. Quote
alanjt Posted July 14, 2010 Posted July 14, 2010 Yeah, they're not well documented. I was working on them about the same time we made the switch to 09 and I found the built-in layerstate functions, I abandoned these. I did post this a while back... http://www.cadtutor.net/forum/showthread.php?t=39986 Quote
Recommended Posts
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.