Author Topic: Using _colordlg  (Read 308 times)

0 Members and 1 Guest are viewing this topic.

jlogan02

  • Newt
  • Posts: 137
Using _colordlg
« 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?
J. Logan
ACAD 2018

I am one with the Force and the Force is with me.
AutoCAD Map 2018 Windows 10

framednlv

  • Mosquito
  • Posts: 9
Re: Using _colordlg
« Reply #1 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

BIGAL

  • Bull Frog
  • Posts: 443
  • 30 + years of using Autocad
Re: Using _colordlg
« Reply #2 on: February 18, 2020, 07:18:01 PM »
Not sure if over complicated.

(setvar 'cecolor (rtos (acad_colordlg 1) 2 0))
(command "line")
A man who never made a mistake never made anything

jlogan02

  • Newt
  • Posts: 137
Re: Using _colordlg
« Reply #3 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")
J. Logan
ACAD 2018

I am one with the Force and the Force is with me.
AutoCAD Map 2018 Windows 10

ronjonp

  • Needs a day job
  • Posts: 7126
Re: Using _colordlg
« Reply #4 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. )
« Last Edit: February 19, 2020, 12:40:28 PM by ronjonp »

Windows 10 x64 - AutoCAD /C3D 2020

Custom Build PC