Jump to content

How to check if color of object is set to rgb


ziele_o2k

Recommended Posts

As topic says, how to check if object color is set to rgb.

For example if I will manually set rgb color to 255,255,0 (yellow) - how to verify that this is true color and not aci?

Link to comment
Share on other sites

...And without DXF 430 (Colour Book)

(defun rgb-p ( ent / enx )
   (and (setq enx (entget ent))
        (assoc 420 enx)
        (not (assoc 430 enx))
   )
)

Link to comment
Share on other sites

In meantime I started digging and I have new knowledge about true colors in acad :)

 

(defun rgb-p ( obj / c )
 (and
   (=  (vla-get-colormethod (setq c (vla-get-truecolor obj))) 
       194
   )
   (= (vla-get-ColorName c) "")
 )
)

Link to comment
Share on other sites

Heres how I'd write it:

 

; (rgbp (vlax-ename->vla-object (car (entsel))))
(defun rgbp ( o / c r )
 (and
   (setq c (vlax-get o 'TrueColor))
   (eq (vlax-get c 'ColorMethod) acColorMethodByRGB) 
   (eq (vlax-get c 'ColorName) "")
   (setq r (mapcar ''((x) (vlax-get c x)) '(Red Green Blue)))
 ); and
 (and c (vl-catch-all-apply 'vlax-release-object (list c)))
 r 
); defun rgbp

 

But I'm not sure if the true color object property has to be released, justin case approach..

And would return either the rgb value or nil (if you require boolean return your will be faster).

Link to comment
Share on other sites

But I'm not sure if the true color object property has to be released, justin case approach..

 

In reference to Autolisp help:

When an AutoLISP routine no longer uses an object outside AutoCAD, such as a Microsoft Excel object, call the vlax-release-object function to make sure that the associated application closes properly.

So in my opinion you do not have to release color object because this is existing object and you are reading only it's properties.

But now I have question, when do you guys are using vlax-release-object.

I'm doing that only when I'm:

- making truecolor object "AutoCAD.AcCmColor...."

- playing with Excel

- playing with XML

Link to comment
Share on other sites

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