Jump to content
Troispistols

Selected Objects to color# LISP

Recommended Posts

Troispistols

Hi guys i'm trying to figure out how to make this lisp and I'm just not able to get it done

 

I would like a lisp to do this by launching "CHC"

 

- Select objects (or objects could be already selected when launching the CHC lisp)

 

- Question asked: "Which color ?" (answering a color number)

 

- If number is 256 or more (its wrong) and the question has to be reasked to get a number between 1 and 255.

 

-Change selection set to the color# answered

 

I've try this but it doesnt work :

 

(defun c:chc ( / obj col#)
(setq cmdecho 0)
(setq obj (ssget))
(setq col# (getint "\nQuelle couleur ? : "))

(if (< col# 255) (setq col# (getint "\nQuelle couleur ? : " (command "change" obj "" "properties" "color" col# "")))

)
(princ)
)

 

Thanks!

Share this post


Link to post
Share on other sites
Tharwat

Try it this way instead .

 

(defun c:chc (/ c s i e)
 (if (and (setq c (acad_colordlg 256))
          (progn (princ "\n Select object to change thei colors ")
                 (setq s (ssget "_:L"))
          )
     )
   (repeat (setq i (sslength s))
     (setq e (entget (ssname s (setq i (1- i)))))
     (entmod (append e (list (cons 62 c))))
   )
 )
 (princ)
)

Share this post


Link to post
Share on other sites
Troispistols
How many people know what color is associated with what color number?

 

Lee Mac came up with this lisp routine for another thread where a similar question was asked.

 

http://www.cadtutor.net/forum/showthread.php?43839-Lisp-to-change-all-objects-with-a-certain-color-to-another-color

 

I does, our plot setup use color for lineweight. Often I force color on objects.

 

Thanks I'll check it out

Share this post


Link to post
Share on other sites
ReMark

OK...so maybe you do. Do your colleagues know all the color numbers?

 

Does it make sense to override layer colors?

Share this post


Link to post
Share on other sites
Troispistols
Try it this way instead .

 

(defun c:chc (/ c s i e)
 (if (and (setq c (acad_colordlg 256))
          (progn (princ "\n Select object to change thei colors ")
                 (setq s (ssget "_:L"))
          )
     )
   (repeat (setq i (sslength s))
     (setq e (entget (ssname s (setq i (1- i)))))
     (entmod (append e (list (cons 62 c))))
   )
 )
 (princ)
)

 

Great, can you make that I can type number instead and add the option for the pop up by typing "C" for if I don't remeber my color number?

If not, I'll take it like this.

Great work

Thanks a lot for the fast answers! :D

Share this post


Link to post
Share on other sites
David Bethel

I'd look into (acad_colordlg )

 

-David

Share this post


Link to post
Share on other sites
Troispistols
OK...so maybe you do. Do your colleagues know all the color numbers?

 

Does it make sense to override layer colors?

 

They do. We have a chart and for a specific lineweight, we have ±2 color number. Steps of ±0.1.

 

It makes sense for us to override layer colors for hidden parts that we have to see thinner. Not everything is forced in the drawing!

Share this post


Link to post
Share on other sites
ReMark

Wouldn't it make more sense to have a layer called Hidden with an assigned color like grey for example?

Share this post


Link to post
Share on other sites
Tharwat
Great, can you make that I can type number instead and add the option for the pop up by typing "C" for if I don't remeber my color number?

If not, I'll take it like this.

Great work

Thanks a lot for the fast answers! :D

This... ?

 

(defun c:chc (/ s i e)
 (if (not c)
   (setq c 1)
 )
 (while
   (not (< 0
           (setq
             c
              (cond
                ((getint (strcat "\n Specify color between [1-255] ( "
                                 (itoa c)
                                 " ) : "
                         )
                 )
                )
                (t c)
              )
           )
           255
        )
   )
    (princ "\n Number of color must be between [1-255] ")
 )
 (if
   (and
     c
     (progn (princ "\n Select object to change thei colors ")
            (setq s (ssget "_:L"))
     )
   )
    (repeat (setq i (sslength s))
      (setq e (entget (ssname s (setq i (1- i)))))
      (entmod (append e (list (cons 62 c))))
    )
 )
 (princ)
)

Share this post


Link to post
Share on other sites
Troispistols
Wouldn't it make more sense to have a layer called Hidden with an assigned color like grey for example?

 

And double or triple how many layers ?

 

Not.

Share this post


Link to post
Share on other sites
Troispistols
This... ?

 

(defun c:chc (/ s i e)
 (if (not c)
   (setq c 1)
 )
 (while
   (not (< 0
           (setq
             c
              (cond
                ((getint (strcat "\n Specify color between [1-255] ( "
                                 (itoa c)
                                 " ) : "
                         )
                 )
                )
                (t c)
              )
           )
           255
        )
   )
    (princ "\n Number of color must be between [1-255] ")
 )
 (if
   (and
     c
     (progn (princ "\n Select object to change thei colors ")
            (setq s (ssget "_:L"))
     )
   )
    (repeat (setq i (sslength s))
      (setq e (entget (ssname s (setq i (1- i)))))
      (entmod (append e (list (cons 62 c))))
    )
 )
 (princ)
)

 

Yes! Can I do something to open the pop up color menu if don't remember the color#?

 

Could be :

 

Specify color between [1-255] or Select Color :

 

Thanks

Share this post


Link to post
Share on other sites
ReMark

All my "hidden" lines go on one layer called, strangely enough, Hidden. If you were do the drawing on a drafting board would you use different colors for all the hidden lines? Would a hidden line depicting a wall that was obscured be shown any different than a hidden line depicting another object? Sometimes we go out of our way to make things difficult. Do you plot in color as well?

Share this post


Link to post
Share on other sites
neophoible
Yes! Can I do something to open the pop up color menu if don't remember the color#?

 

Could be :

 

Specify color between [1-255] or Select Color :

 

Thanks

Yes, it should be possible to do this. A simple approach would be to change the current color via COLOR, then CHANGE the Property Color to the current value (CECOLOR).

Share this post


Link to post
Share on other sites
neophoible

For anyone who wanders in, this was the basic idea I was talking about. It allows just the standard colors 1 through 255 (no ByBlock or ByLayer). Note that the system variable CECOLOR is a string.

 

(defun C:CHC (/ ColorObjects CurrColorOrg NewColor CmdEchoOrg)
 (prompt "\nSelect objects to color...")
 (cond
   ( (setq ColorObjects (ssget))
     (setq CurrColorOrg (getvar 'CECOLOR)
           CmdEchoOrg   (getvar 'CMDECHO)
     )
     (setvar 'CMDECHO 0)    
     (while
       (not (cond
       ( (initget 6) )   
           ( (setq NewColor (getint
               "\nEnter object color (1-255) <dialog>: "
             )              )
             (if (< NewColor 256) (setvar 'CECOLOR (itoa NewColor)))
           )
           (T(initdia)
             (command "_.COLOR")
             (numberp (read (getvar 'CECOLOR)))
           )                                  
       )    )
       (prompt "\nCannot set color to that value.\n*Invalid.*")  
     )  
     (command "_.CHANGE" ColorObjects "" "_P" "_C" (getvar 'CECOLOR) "") 
 ) )
 (setvar 'CECOLOR CurrColorOrg)
 (setvar 'CMDECHO CmdEchoOrg)      
 (princ)
)

Share this post


Link to post
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now

×