Color Translator Lisp needed!!!

Discussion in 'AutoCAD' started by JonEast, Jun 15, 2004.

  1. JonEast

    JonEast Guest

    Been a while since the old lips routine class in college and need some help! I'm in need of a quick lisp routine that converts a specified color to another color but leaves the object(s) on the same layer. Currently there are 5 different colors on one layer (details). Ex. Color #1 (red) needs to switch to color #10.
     
    JonEast, Jun 15, 2004
    #1
  2. JonEast

    T.Willey Guest

    You want to get the assoc code 62, if there isn't one then it is bylayer (I think). Once you get the one you want, substitute the new for the old with "entmod".

    Tim
     
    T.Willey, Jun 15, 2004
    #2
  3. JonEast

    Jason Wilder Guest

    Correct, if there isn't a color 62, then it's bylayer for the object.

    You're right, just chance the 62 code and you're done.

    (I think). Once you get the one you want, substitute the new for the old
    with "entmod".
     
    Jason Wilder, Jun 15, 2004
    #3
  4. JonEast

    Don Butler Guest

    This will change all RED objects on your layer to 10.

    Beware of locked layers...

    (setq ss (ssget "x" (list (cons 8 "YOURLAYER")(cons 62 1))))
    (vl-cmdf "._CHPROP" ss "" "C" 10 "")


    Don


    help! I'm in need of a quick lisp routine that converts a specified color to
    another color but leaves the object(s) on the same layer. Currently there
    are 5 different colors on one layer (details). Ex. Color #1 (red) needs to
    switch to color #10.
     
    Don Butler, Jun 16, 2004
    #4
  5. JonEast

    Don Butler Guest

    By the way, I still remember the old LIPS routine too!

    Don
     
    Don Butler, Jun 16, 2004
    #5
  6. If you want to pick objects to be updated, rather than have all of them
    changed as in Don Butler's offering, you can save the assoc 62 value to a
    variable, for instance

    (setq currentcolor (cdr (assoc 62 (entget (car (entsel)))))) <pick the
    item>

    then you can do some simple (if) statements if you only have a few colors to
    deal with:

    (if (= currentcolor 1) (setq newcolor 10))
    (if (= currentcolor 2) (setq newcolor <whatever>))
    .... etc. ...

    Then entmod/entupd the newcolor into the entity.

    Kent Cooper, AIA


    I give them a new color number.
     
    Kent Cooper, AIA, Jun 16, 2004
    #6
  7. JonEast

    JonEast Guest

    Hope this clears some items up.

    Currently there are items drawn in the following colors, red, green, cyan, magenta and white and all are on the same layer (details). I need a lisp to filter these colors and so they change to the following colors (red to 10), (green to 100), (cyan to 130), (magenta to 210) and (white to 255).
    ***This is all due to coordinate pen settings between different locations.***

    Here's what I have so far but this seems to change everything to red.

    (DEFUN C:CHC (/ ss)
    (prompt "\n..Select Entities for 'Color red'.")
    (setq ss (ssget))
    (COMMAND ".CHANGE" ss "" "P" "C" "10" "")
    ;(princ)
    )
    (princ)
     
    JonEast, Jun 16, 2004
    #7
  8. JonEast

    Don Butler Guest

    He said he wanted to translate the color and that's why I opted to change
    them all. I was also trying to keep the code as simple as possible as he
    said he was inexperienced.

    Don
     
    Don Butler, Jun 16, 2004
    #8
  9. JonEast

    Don Butler Guest

    (defun c:LayTran (/ ss idx obj col)
    (vl-load-com)
    (setq ss (ssget (list (cons 8 "DETAILS"))))
    (if ss
    (progn
    (setq idx 0)
    (repeat (sslength ss)
    (setq obj (vlax-ename->vla-object (ssname ss idx)))
    (setq col (vla-get-color obj))
    (cond
    ((= col 1)(vla-put-color obj 10))
    ((= col 3)(vla-put-color obj 100))
    ((= col 4)(vla-put-color obj 130))
    ((= col 6)(vla-put-color obj 210))
    ((= col 7)(vla-put-color obj 255))
    )
    (setq idx (1+ idx))
    )
    )
    )
    (princ)
    )

    Don


    magenta and white and all are on the same layer (details). I need a lisp to
    filter these colors and so they change to the following colors (red to 10),
    (green to 100), (cyan to 130), (magenta to 210) and (white to 255).
     
    Don Butler, Jun 16, 2004
    #9
  10. JonEast

    ECCAD Guest

    Here ya go.

    (defun chg_colors ( SS )
    (setq ss (ssget "x" (list (cons 8 "DETAILS")(cons 62 1)))); get RED
    (if ss (command "._CHPROP" ss "" "_c" 10 "")); change to 10
    (setq ss (ssget "x" (list (cons 8 "DETAILS")(cons 62 3)))); get GREEN
    (if ss (command "._CHPROP" ss "" "_c" 100 "")); change to 100
    (setq ss (ssget "x" (list (cons 8 "DETAILS")(cons 62 4)))); get CYAN
    (if ss (command "._CHPROP" ss "" "_c" 130 "")); change to 130
    (setq ss (ssget "x" (list (cons 8 "DETAILS")(cons 62 6)))); get MAGENTA
    (if ss (command "._CHPROP" ss "" "_c" 210 "")); change to 210
    (setq ss (ssget "x" (list (cons 8 "DETAILS")(cons 62 7)))); get WHITE
    (if ss (command "._CHPROP" ss "" "_c" 255 "")); change to 255
    (command "_regen")
    (princ)
    ); end function
    ;; call for use: (chg_colors)

    Bob
     
    ECCAD, Jun 16, 2004
    #10
  11. JonEast

    ECCAD Guest

    Correction:
    (defun chg_colors ( / SS )

    Bob
     
    ECCAD, Jun 16, 2004
    #11
  12. JonEast

    JonEast Guest

    Bob,

    I added this to my acad2005doc.lsp file but when I use it in AutoCAD I get the following

    Command: chg_colors
    Unknown command "CHG_COLORS". Press F1 for help.
     
    JonEast, Jun 16, 2004
    #12
  13. JonEast

    ECCAD Guest

    Jon:eek:r do:
    (defun C:chg_colors ( / ss )

    and then you can call it on command line.
    Command: chg_colors

    Or leave it as is and:
    Command: (chg_colors)

    Bob
     
    ECCAD, Jun 16, 2004
    #13
  14. JonEast

    Don Butler Guest

    Hey Luis. ¿Cómo usted ha sido?

    You're definitely right about TrueColor.

    I know I should be doing what you've done but I've been putting it off.

    What do you think about just checking to see if the TrueColor property is
    available so the code is not release dependent ("acadver")?

    Don
     
    Don Butler, Jun 16, 2004
    #14
  15. JonEast

    Don Butler Guest

    I understand.

    Don

     
    Don Butler, Jun 16, 2004
    #15
  16. JonEast

    JonEast Guest

    Don,

    Thank you for the information on the lisp routine it's perfect, you just save me hours of translation work!!
     
    JonEast, Jun 16, 2004
    #16
  17. JonEast

    JonEast Guest

    Bob,

    I made some changes as you had said but this is what I get when initiating the command.


    AutoCAD Express Tools Copyright © 2002-2004 Autodesk, Inc.

    AutoCAD menu utilities loaded.
    Command: CHG_COLORS
    ; error: too few arguments

    Command:
    Command: (CHG_COLORS)
    ; error: no function definition: CHG_COLORS
     
    JonEast, Jun 16, 2004
    #17
  18. JonEast

    Don Butler Guest

    You're welcome.

    Don

    save me hours of translation work!!
     
    Don Butler, Jun 16, 2004
    #18
  19. JonEast

    JonEast Guest

    Bob,

    Figured it out. (/ SS) vs ( / SS) No space after parenthesis.

    Thanks for your help!
     
    JonEast, Jun 16, 2004
    #19
  20. JonEast

    GaryDF Guest

    CTRAN.lsp is a dialog base routine that will do what you want....saves settings
    to
    a file for reuse. Can't remember the original author. I will try and find the
    original
    version over the weekend. I have one that I have modified. Works great.

    Gary


    I'm in need of a quick lisp routine that converts a specified color to another
    color but leaves the object(s) on the same layer. Currently there are 5 different
    colors on one layer (details). Ex. Color #1 (red) needs to switch to color #10.
     
    GaryDF, Jun 18, 2004
    #20
Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments (here). After that, you can post your question and our members will help you out.