TheSwamp

Code Red => AutoLISP (Vanilla / Visual) => Topic started by: csgoh on July 12, 2006, 08:34:00 PM

Title: Setting Layer Problem & Handle->vla-object.
Post by: csgoh on July 12, 2006, 08:34:00 PM
Question 1.
I wrote this function a to thaw,on and unlock.    However, whenever the layer is a current layer, it gives me an "Automation Error. Invalid layer". Any remedy to the problem is much appreciated.
Code: [Select]
;; ========================================================
;; wg:activate-layer
;; function to turn on, thaw and unlock if layers exist.
;;
(defun WG:activate-layer (lan1 objLayers / layer)
  (cond ((not (vl-catch-all-error-p (setq layer (vl-catch-all-apply 'vla-item (list objLayers lan1)))))
         (vla-put-Freeze layer ':vlax-false)
         (vla-put-Layeron layer ':vlax-true)
         (vla-put-Lock layer ':vlax-false)
         (princ (strcat "\nLayer " lan1 " on,thawed & unlocked ....")
         )
        )
  )
) ;_WG:activate-layer


Question 2.
How do one convert a handle to a vla-object?

Thanks.
Title: Re: Setting Layer Problem & Handle->vla-object.
Post by: Jeff_M on July 12, 2006, 09:48:38 PM
1. You cannot use the Freeze property on the ActiveLayer, rather you can query it but you cannot set it....even if it's to false. So just add a check to see if lan1 is current before setting that property.

2. (vla-handletoobject (vla-get-activedocument (vlax-get-acad-object)) handle)