Change color of selected objects with dialogbox

Change color of selected objects with dialogbox

Angelswing91
Contributor Contributor
949 Views
3 Replies
Message 1 of 4

Change color of selected objects with dialogbox

Angelswing91
Contributor
Contributor

Hi all, 

i tried to change color of selected objects (not layer) with dialogbox... it appers, but nothing changes. 😞

(defun c:spa ()
(if
(setq p1 (cadr (ssgetfirst)))
(progn (sssetfirst) (setq p1 (acad_colordlg 5 t)))
)
(princ)
)

Can somebody help me?

0 Likes
950 Views
3 Replies
Replies (3)
Message 2 of 4

Kent1Cooper
Consultant
Consultant

@Angelswing91 wrote:

…. i tried to change color of selected objects (not layer) with dialogbox... it appers, but nothing changes....


You are simply changing what the 'p1' variable contains from a selection set to a number, rather than applying  that as a color number to  that selection set.  And nothing will happen if there is no pre-selection.  Try something like this [untested]:

 

(defun c:spa (/ p1)
  (if
    (setq p1 (cond ((cadr (ssgetfirst))) ((ssget))))
      ; if there's anything pre-selected, use it; otherwise, ask for selection
    (progn
      (sssetfirst) ; clear selection/grip/highlight
      (command "_.chprop" p1 "" "_color" (acad_colordlg 5 t) "")
    ); progn
  ); if
  (princ)
); defun

 

Kent Cooper, AIA
0 Likes
Message 3 of 4

dlanorh
Advisor
Advisor
(defun c:spa ( / cdrs sel c el)
  
  (defun cdrs (dxf lst) (cdr (assoc dxf lst)))
  
  (cond ( (setq sel (entsel "\nSelect Entity : "))
          (setq c (acad_colordlg 5 t) el (entget (car sel)))
          (if (cdrs 62 el) (entmod (setq el (subst (cons 62 c) (assoc 62 el) el))) (entmod (setq el (append el (list (cons 62 c))))))
        )
        (t (princ "\nNothing Selected"))
  )
  (princ)
)

I am not one of the robots you're looking for

0 Likes
Message 4 of 4

pbejse
Mentor
Mentor

@Angelswing91 wrote:

i tried to change color of selected objects (not layer) with dialogbox... it appers, but nothing changes. 😞


 

I like to think there's more to this than just changing colors, why else would you not use toolbar or ribbon? Select object and ..

colordlg.png

 

Please tell us more.

 

@dlanorh 

FWIW You dont need all this

(setq c	 (acad_colordlg 5 t)
      el (entget (car sel))
)
(if (cdrs 62 el)
  (entmod (setq el (subst (cons 62 c) (assoc 62 el) el)))
  (entmod (setq el (append el (list (cons 62 c)))))
)

This would be enough regardless 62 exists or not

	 (setq c  (acad_colordlg 5 t)
	       el (entget (car sel))
	 )
	 (entmod (append el (list (cons 62 c))))
	)

HTH

0 Likes