TheSwamp

Code Red => AutoLISP (Vanilla / Visual) => Topic started by: jlogan02 on February 18, 2020, 06:29:11 PM

Title: Using _colordlg
Post by: jlogan02 on February 18, 2020, 06:29:11 PM
Trying to understand the use of
Code - Auto/Visual Lisp: [Select]
  1. _colordlg

Lets me choose a color but does not draw the line in the chosen color. If the color dialog opens
with the current color as Green, that's what color the line is drawn in, regardless of my choice.

Code - Auto/Visual Lisp: [Select]
  1. (defun C:choice (/ COLOR)
  2.   (if
  3.     (setq COLOR
  4.       (acad_colordlg
  5.         (cond ; since the number argument needs to be an integer,
  6.           ; but the CECOLOR System Variable is a text string:
  7.           ((= (getvar 'cecolor) "BYLAYER") 256)
  8.           ((= (getvar 'cecolor) "BYBLOCK") 0)
  9.           ((atoi (getvar 'cecolor)))
  10.         ); cond
  11.         T ; allow BYLAYER/BYBLOCK choices
  12.       ); acad_colordlg
  13.     ); setq
  14.           (command "Line" "_color" "")
  15.   ); if
  16.   (princ)
  17. ); defun

What am I missing?
Title: Re: Using _colordlg
Post by: framednlv on February 18, 2020, 07:02:48 PM
I'm not the best but I'll give it a try:
Code: [Select]
(defun C:choice (/ COLOR)
  (if
    (setq COLOR
      (acad_colordlg
        (cond ; since the number argument needs to be an integer,
          ; but the CECOLOR System Variable is a text string:
          ((= (getvar 'cecolor) "BYLAYER") 256)
          ((= (getvar 'cecolor) "BYBLOCK") 0)
          ((atoi (getvar 'cecolor)))
        ); cond
        T ; allow BYLAYER/BYBLOCK choices
      ); acad_colordlg
    ); setq
          (command "Line" "'color" COLOR );;;added transparent command for color and removed the extra quotes
  ); if
  (princ)
); defun
Title: Re: Using _colordlg
Post by: BIGAL on February 18, 2020, 07:18:01 PM
Not sure if over complicated.

(setvar 'cecolor (rtos (acad_colordlg 1) 2 0))
(command "line")
Title: Re: Using _colordlg
Post by: jlogan02 on February 18, 2020, 08:15:36 PM
This worked well. Thanks BIGAL.

Not sure if over complicated.

(setvar 'cecolor (rtos (acad_colordlg 1) 2 0))
(command "line")
Title: Re: Using _colordlg
Post by: ronjonp on February 19, 2020, 12:34:27 PM
You can also do something like this so you don't mess with system variables, as well as use truecolor and colorbooks and it will remember the last color used across sessions.
Code - Auto/Visual Lisp: [Select]
  1. (defun c:choice (/ a b c r)
  2.   (or (getenv (setq r "ColorLine")) (setenv r "(62 . 1)"))
  3.   (if (setq c (acad_truecolordlg (read (getenv r))))
  4.            (while (and (or a (setq a (getpoint "\nSpecify start point: ")))
  5.                        (setq b (getpoint a "\nSpecify next point: "))
  6.                   )
  7.              (entmakex (append (list '(0 . "line") (cons 10 a) (cons 11 (setq a b))) c))
  8.            )
  9.     )
  10.   )
  11.   (princ)
  12. )