Author Topic: change objects colour and line type  (Read 1020 times)

0 Members and 1 Guest are viewing this topic.

alloy mold design

  • Mosquito
  • Posts: 8
  • Automotive wheel mold design
change objects colour and line type
« 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. )
m Foshan City, Guangdong Province, China, car wheels mold design

framednlv

  • Newt
  • Posts: 64
Re: change objects colour and line type
« Reply #1 on: June 16, 2022, 10:19:06 AM »
It worked for me. What error do you get?

mhupp

  • Bull Frog
  • Posts: 250
Re: change objects colour and line type
« Reply #2 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. )

BIGAL

  • Swamp Rat
  • Posts: 1392
  • 40 + years of using Autocad
Re: change objects colour and line type
« Reply #3 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.
« Last Edit: June 17, 2022, 09:48:36 PM by BIGAL »
A man who never made a mistake never made anything

alloy mold design

  • Mosquito
  • Posts: 8
  • Automotive wheel mold design
Re: change objects colour and line type
« Reply #4 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.
m Foshan City, Guangdong Province, China, car wheels mold design

BIGAL

  • Swamp Rat
  • Posts: 1392
  • 40 + years of using Autocad
Re: change objects colour and line type
« Reply #5 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 "")
)
A man who never made a mistake never made anything

alloy mold design

  • Mosquito
  • Posts: 8
  • Automotive wheel mold design
Re: change objects colour and line type
« Reply #6 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 "")
)
m Foshan City, Guangdong Province, China, car wheels mold design

BIGAL

  • Swamp Rat
  • Posts: 1392
  • 40 + years of using Autocad
Re: change objects colour and line type
« Reply #7 on: June 19, 2022, 12:37:27 AM »
Have a look at this (setq col (acad_colordlg 1)) just paste to command line.
A man who never made a mistake never made anything