Jump to content

Recommended Posts

Posted

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! :)

Posted

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. :)

Posted

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?

rl1o.jpg

 

Uploaded with ImageShack.us

Posted

The LayerState functions weren't introduced until '09, I think.

Posted

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

Posted
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!

Posted
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.

Posted
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!

Posted

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.

Posted
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.

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
Unfortunately, your content contains terms that we do not allow. Please edit your content to remove the highlighted words below.
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  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...