ssget Associative code for selecting Color

Discussion in 'AutoCAD' started by Thomas Plant, Nov 2, 2004.

  1. Thomas Plant

    Thomas Plant Guest

    I'm trying to create a lisp routine that will select all objects on a layer
    that is a specified color. I found something that said the associative code
    for color is 62 but it's giving me an error. Can someone help.

    This is the line I'm using.

    OldLayer and Color are variables

    (setq Select (ssget "X" (list (cons 8 OldLayer)(cons 62 Color))))

    this is the error I get.

    Command: ; error: bad SSGET list value

    If I take out the (cons 62 Color) it does work on taking all objects on the
    old layer name to the new layer name. So I know the error is with the code
    62.

    Thanks.

    Thomas
     
    Thomas Plant, Nov 2, 2004
    #1
  2. As I recall, a drawing entity will have an (assoc 62) value ONLY if the
    entity has an explicit color assigned to it. If its color is BYLAYER, there
    will not be a code 62 in its association list at all, which (if all objects
    on the layer are colored BYLAYER) might be why it's giving you that error
    message, and why it works when you remove the (cons 62 ...). Then it finds
    everything on that layer, whether its color is BYLAYER or something else.
     
    Kent Cooper, AIA, Nov 2, 2004
    #2
  3. I suspect that the color number is being passed
    as something other than an integer.

    Command: (ssget "x" '((62 . "1")))
    ; error: bad SSGET list value

    Command: (ssget "x" '((62 . 1)))
    nil
     
    Jason Piercey, Nov 2, 2004
    #3
  4. Thomas Plant

    T.Willey Guest

    Thomas,

    This works for me. (ssget (list (cons 0 "insert") (cons 62 1))) I think you just have to make sure you are passing it the things it wants. In your example "OldLayer" has to be a string, and "Color" has to be a integer.

    Hope that helps.
    Tim
     
    T.Willey, Nov 2, 2004
    #4
  5. Thomas Plant

    Thomas Plant Guest

    The DWG is a file that was converted from Microstation, so all objects
    colors are forced. I have a layer that has concrete and pavement on it.
    The color for concrete is blue and the color for pavement is white. I
    wanted to write a lisp program to take all the white objects on this layer
    and put them on a different layer. I have other layers done the same way
    for other things.
    This is what I have so far.


    (Defun C:chlayerfil (/ Select Count OldLayer NewLayer Color LineType)

    (if (not (setq Select (ssget "_i")))
    (progn
    (setq OldLayer (strcase (getstring "\nEnter Old Layer Name ")))
    (setq NewLayer (strcase (getstring "\nEnter New Layer Name ")))
    (setq Color (strcase (getstring "\nEnter Color of Objects ")))

    (command "layer" "on" OldLayer "Thaw" OldLayer "Unlock" OldLayer "")

    (setq Select (ssget "X" (list (cons 8 OldLayer)(cons 62 Color))))
    )
    )

    (if Select
    (progn
    (setq Count (sslength Select))
    )
    )

    (if Select
    (progn
    (command "_.chprop" Select "" "_la" NewLayer "")

    (prompt (strcat "\n" (itoa (sslength Select)) " objects changed to
    layer " NewLayer "."))
    )
    )

    (princ)
    )

    Any ideas.

    Thanks
     
    Thomas Plant, Nov 2, 2004
    #5
  6. Thomas Plant

    Thomas Plant Guest

    That is what it was. I was trying to pass the color as a string and type in
    the color name. I changed it to an integer type and use the color code and
    that works.

    Thanks.
     
    Thomas Plant, Nov 2, 2004
    #6
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.