Author Topic: Difference between vla-put-color and vla-put-truecolor  (Read 5853 times)

0 Members and 1 Guest are viewing this topic.

mailmaverick

  • Bull Frog
  • Posts: 493
Difference between vla-put-color and vla-put-truecolor
« 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))

irneb

  • Water Moccasin
  • Posts: 1794
  • ACad R9-2016, Revit Arch 6-2016
Re: Difference between vla-put-color and vla-put-truecolor
« Reply #1 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))
Common sense - the curse in disguise. Because if you have it, you have to live with those that don't.

mailmaverick

  • Bull Frog
  • Posts: 493
Re: Difference between vla-put-color and vla-put-truecolor
« Reply #2 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 ?

Lee Mac

  • Seagull
  • Posts: 12912
  • London, England
Re: Difference between vla-put-color and vla-put-truecolor
« Reply #3 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)
)

mailmaverick

  • Bull Frog
  • Posts: 493
Re: Difference between vla-put-color and vla-put-truecolor
« Reply #4 on: April 13, 2014, 07:59:16 AM »
Thanks Lee,

You are always genius.

Lee Mac

  • Seagull
  • Posts: 12912
  • London, England
Re: Difference between vla-put-color and vla-put-truecolor
« Reply #5 on: April 13, 2014, 08:04:10 AM »
You're welcome mailmaverick, though I am far from a genius  :wink:

mailmaverick

  • Bull Frog
  • Posts: 493
Re: Difference between vla-put-color and vla-put-truecolor
« Reply #6 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