Autolisp Codes:
(defun c:Sl(/ old_cmh sel ent laynme )
;;Author:Ganesh Shetty, Copyright © 2013 -http://autolispgs.blogspot.in
(setq old_cmh(getvar 'cmdecho))
(setvar 'cmdecho 0)
(if (setq sel (car (entsel "\nSelect an Object to set Layer Current:")))
(progn
(setq ent(entget sel))
(setq laynme(cdr (assoc 8 ent)))
(command "_Layer" "set" laynme "")
(princ (strcat "\nLayer \"" laynme "\" is Current Now:"))
)
)
(setvar 'cmdecho oldcmh)
(princ)
)
Visual Lisp Codes:
(defun c:Sl (/ *Activedoc* *Layers* ename Sel);(S)et (L)ayer
;;Author:Ganesh Shetty, Copyright © 2013 -http://autolispgs.blogspot.in
(vl-load-com) ;loading Activex Support
(setq *Activedoc* (vlax-get-property
(vlax-get-acad-object)
'Activedocument
)
*Layers* (vlax-get-property *Activedoc* 'Layers)
)
(if (setq sel (car (entsel "\nSelect an Object to Set layer Current:")))
(progn
(setq ename(vlax-ename->vla-object sel))
(vla-put-activelayer *Activedoc* (vla-item *layers* (vla-get-layer ename)))
(princ (strcat "\nLayer \"" (vla-get-layer ename) "\" is Current Now:"))
)
)
(princ)
)