Author Topic: layer color  (Read 2141 times)

0 Members and 1 Guest are viewing this topic.

Andrea

  • Water Moccasin
  • Posts: 2372
layer color
« on: January 03, 2005, 09:49:14 PM »
Hi all...

I need to get the color of a specific layer in LISP...

any idea how ??

thanks.
Keep smile...

daron

  • Guest
layer color
« Reply #1 on: January 03, 2005, 11:46:01 PM »
Yeah, ask it in the proper forum. Nevermind, I'll move you to it. Hmm. How do you intend to get the info out of the layer? I believe the activex route makes it easier, but I can't look, don't have cad here. I'm sure dxf will give it to you if it's not bylayer. I believe the dxf value you would look for is 62. Someone correct me if I'm wrong.

Kerry

  • Mesozoic relic
  • Seagull
  • Posts: 11654
  • class keyThumper<T>:ILazy<T>
layer color
« Reply #2 on: January 04, 2005, 01:35:56 AM »
This should give you the idea :
Code: [Select]

;;;------------------------------------------------------------------
;;;------------------------------------------------------------------
;;; return the item if existing, or nil
;;; kwb 20050104

(defun kbpf:safeitem (collection item / returnvalue)
  (if (not (vl-catch-all-error-p
             (setq returnvalue
                    (vl-catch-all-apply 'vla-item (list collection item)))
           )
      )
    returnvalue
  )
)

;;;------------------------------------------------------------------
;;;------------------------------------------------------------------
;;; return the color of the named layer, or nil
;;; Does not allow explicitly for TrueColor RGB colors.
;;; kwb 20050104

(defun get_LayerColor (sLayerName / oLayer oColor)
  (if (setq oLayer (kbpf:safeitem
                     (vla-get-layers
                       (vla-get-activedocument (vlax-get-acad-object))
                     )
                     sLayerName
                   )
      )
    (setq oColor (vla-get-color oLayer))
  )
  oColor
)

;;;------------------------------------------------------------------
;;;------------------------------------------------------------------
;;; kwb 20050104

(defun c:test (/ result)
  (foreach sLayerName '("0" "DoesNotExist")
    (if (setq result (get_LayerColor sLayerName))
      (alert (strcat "Color for Layer '" slayerName "' : " (itoa result)))
      (alert (strcat "Color for Layer '" slayerName "' : undetermined "))
    )
  )
)
kdub, kdub_nz in other timelines.
Perfection is not optional.
Everything will work just as you expect it to, unless your expectations are incorrect.
Discipline: None at all.

Andrea

  • Water Moccasin
  • Posts: 2372
layer color
« Reply #3 on: January 04, 2005, 08:23:16 AM »
thanks. Kerry,

I've modified the routine for my use and it work well.

;-)
Keep smile...