TheSwamp

Code Red => AutoLISP (Vanilla / Visual) => Topic started by: alloy mold design on June 16, 2022, 10:09:15 AM

Title: change objects colour and line type
Post by: alloy mold design on June 16, 2022, 10:09:15 AM
Hi,I want to change the objects colour and line type, but I can not change the colour ID when I want. What is this problem? Would you help me? Thank you!

Code - Auto/Visual Lisp: [Select]
  1. (defun C:wg_dd (/ na sobject clo)
  2.   (setq
  3.     sobject (ssget)
  4.   )
  5.   (cond ((equal 'PICKSET (type sobject))
  6.          (command "chprop" sobject "" "c" 6 "LT" "Divide2" "")
  7.         )
  8.         ((equal 'INT (type na))
  9.          (progn
  10.            (setq sobject (ssget))
  11.            (command "chprop" sobject "" "c" na "LT" "Divide2" "")
  12.  
  13.          )
  14.         )
  15.   )
  16.  
  17.   (prin1)
  18. )
Title: Re: change objects colour and line type
Post by: framednlv on June 16, 2022, 10:19:06 AM
It worked for me. What error do you get?
Title: Re: change objects colour and line type
Post by: mhupp on June 16, 2022, 01:13:34 PM
Your lisp doesn't really make sense to me.  are col and na set in another lisp?

This might be better flow.
Code - Auto/Visual Lisp: [Select]
  1. (defun C:WG_dd (/ sobject)
  2.   (if (setq sobject (ssget)) ;if something selected change prop
  3.     (command "chprop" sobject "" "c" 6 "LT" "Divide2" "")
  4.     (progn ;else 2nd try at selection ?
  5.       (setq sobject (ssget))
  6.       (command "chprop" sobject "" "c" # "LT" "Divide2" "") ;replace # with color number
  7.     )
  8.   )
  9.   (princ)
  10. )
Title: Re: change objects colour and line type
Post by: BIGAL on June 16, 2022, 11:29:23 PM
I would take a slightly different way

Code: [Select]
(defun chcx (x / sobject)
  (if (setq sobject (entsel "\nPick a object ")) ;if something selected change prop
    (command "chprop" sobject "" "c" x "LT" "Divide2" "")
  )
  (princ)
)

To run type (chcx 6) on command line, yes could do a select color also or make lots of defuns CHC6 CHC4 and so on.
Title: Re: change objects colour and line type
Post by: alloy mold design on June 17, 2022, 09:47:01 AM
Thanks all. only one lisp works. The fuction I want to get is that before or after something selected,I can change the colour ID or not.

I would take a slightly different way

Code: [Select]
(defun chcx (x / sobject)
  (if (setq sobject (entesel "\nPick a object ")) ;if something selected change prop
    (command "chprop" sobject "" "c" x "LT" "Divide2" "")
  )
  (princ)
)

To run type (chcx 6) on command line, yes could do a select color also or make lots of defuns CHC6 CHC4 and so on.
Title: Re: change objects colour and line type
Post by: BIGAL on June 17, 2022, 09:48:21 PM
Sorry there was a typo it should have  been entsel.

A few defuns if you want to go that way.

Code: [Select]
(defun c:ccc6 ( / )
(command "chprop" (entsel "\nPick a object ") "" "c" 6 "")
)

(defun c:ccc5 ( / )
(command "chprop" (entsel "\nPick a object ") "" "c" 5 "")
)

(defun c:ccc4 ( / )
(command "chprop" (entsel "\nPick a object ") "" "c" 4 "")
)
Title: Re: change objects colour and line type
Post by: alloy mold design on June 18, 2022, 10:09:39 PM
Thanks BIGAL. This is another one I wrote.But I want to improve.
Code - Auto/Visual Lisp: [Select]
  1. (defun C:wg_dd (/ sobject clo)
  2.  
  3.   (setq clo (getint));here,I want to select something or not.
  4.   (if (or (null clo) (> clo 9) (< clo 1))
  5.     (setq clo 6)
  6.   );
  7.   (setq sobject (ssget))
  8.   (command "chprop" sobject "" "c" clo "LT" "Divide2" "")
  9.   (prin1)
  10. )
Sorry there was a typo it should have  been entsel.

A few defuns if you want to go that way.

Code: [Select]
(defun c:ccc6 ( / )
(command "chprop" (entsel "\nPick a object ") "" "c" 6 "")
)

(defun c:ccc5 ( / )
(command "chprop" (entsel "\nPick a object ") "" "c" 5 "")
)

(defun c:ccc4 ( / )
(command "chprop" (entsel "\nPick a object ") "" "c" 4 "")
)
Title: Re: change objects colour and line type
Post by: BIGAL on June 19, 2022, 12:37:27 AM
Have a look at this (setq col (acad_colordlg 1)) just paste to command line.