TheSwamp

Code Red => AutoLISP (Vanilla / Visual) => Topic started by: mailmaverick on April 13, 2014, 02:15:11 AM

Title: Difference between vla-put-color and vla-put-truecolor
Post by: mailmaverick on April 13, 2014, 02:15:11 AM
What is the difference between vla-put-color and vla-put-truecolor ?
If I want to change color of certain entities (POLYLINES, TEXT etc), which should I use ?

Also, I want to ask the user about which color to change by using acad_truecolordlg as follows :-

Code: [Select]
  (setq ent (car (entsel)))
  (setq obj (vlax-ename->vla-object ent))
  (setq col (acad_truecolordlg 256))
  (vla-put-truecolor obj col)

But the above gives following error :
error: lisp value has no coercion to VARIANT with this type:  ((62 . 132) (420 . 3126736))
Title: Re: Difference between vla-put-color and vla-put-truecolor
Post by: irneb on April 13, 2014, 02:48:09 AM
Truecolor is a bit more difficult to use. You can't send it the colour index, but need to send it a TrueColor object which is set to that index (or RGB value or colour Name).

For your sample the vla-put-Color would work, it's as if it does the creation of a TrueColor object from the colour index for you. A short-hand way of doing this:
Code - Auto/Visual Lisp: [Select]
  1. (setq col (vla-get-TrueColor obj))
  2. (vla-put-ColorIndex col 256)
  3. (vla-put-TrueColor obj col)
So you can think of vla-put-Color as a defun similar to this:
Code - Auto/Visual Lisp: [Select]
  1. (defun ib:SetColorByIndex (obj index / col)
  2.   (setq col (vla-get-TrueColor obj))
  3.   (vla-put-ColorIndex col index)
  4.   (vla-put-TrueColor obj col))
Title: Re: Difference between vla-put-color and vla-put-truecolor
Post by: mailmaverick on April 13, 2014, 03:20:46 AM
Thanks irneb,

One more question. If the user selects a non-standard colour in acad_truecolordlg i.e. in R,G,B format, then how to change the property of the entity to the user selected color ?
Title: Re: Difference between vla-put-color and vla-put-truecolor
Post by: Lee Mac on April 13, 2014, 05:10:42 AM
One more question. If the user selects a non-standard colour in acad_truecolordlg i.e. in R,G,B format, then how to change the property of the entity to the user selected color ?

In my opinion, it is easier to use Vanilla methods for this task:

Code: [Select]
(defun c:test ( / col idx sel )
    (if
        (and
            (setq sel (ssget "_:L"))
            (setq col (acad_truecolordlg 1))
        )
        (repeat (setq idx (sslength sel))
            (entmod (append (entget (ssname sel (setq idx (1- idx)))) col))
        )
    )
    (princ)
)
Title: Re: Difference between vla-put-color and vla-put-truecolor
Post by: mailmaverick on April 13, 2014, 07:59:16 AM
Thanks Lee,

You are always genius.
Title: Re: Difference between vla-put-color and vla-put-truecolor
Post by: Lee Mac on April 13, 2014, 08:04:10 AM
You're welcome mailmaverick, though I am far from a genius  :wink:
Title: Re: Difference between vla-put-color and vla-put-truecolor
Post by: mailmaverick on April 13, 2014, 08:34:32 AM
Just for record and info of all others viewing this thread, apart from Lee Mac's wonderful solution, I found another solution of getting TRUECOLOR OBJECT at following link :-

http://www.theswamp.org/index.php?topic=35588.0 (http://www.theswamp.org/index.php?topic=35588.0)