Results 1 to 10 of 10

Thread: Selection set of polylines that are a specific color

  1. #1
    Certifiable AUGI Addict ccowgill's Avatar
    Join Date
    2004-08
    Location
    Iron Station, NC
    Posts
    3,198
    Login to Give a bone
    0

    Default Selection set of polylines that are a specific color

    Can someone give me a hand with writing the line that selects all Polylines of a certain color? This is what I have so far and it keeps giving me an error
    ; error: bad SSGET list value

    (setq co (getstring "\nColor to Add?"))
    (setq SSET (ssget (list (cons 0 "*POLYLINE")(cons 62 co)))

  2. #2
    All AUGI, all the time CAB2k's Avatar
    Join Date
    2016-01
    Location
    Brandon, Florida
    Posts
    687
    Login to Give a bone
    0

    Default Re: Selection set of polylines that are a specific color

    This will give you some ideas.
    Code:
    ;;=============================================================
    ;;     cSel.lsp by Charles Alan Butler 
    ;;            Copyright 2005           
    ;;   by Precision Drafting & Design All Rights Reserved.
    ;;        Contact at ab2draft@TampaBay.rr.com   
    ;; 
    ;;    Version 1.0 Beta  July 13,2005 
    ;;
    ;;          C o l o r   S e l e c t    
    ;;   Creates a selection set of objects of a color
    ;;   Objects with color ByLayer are selected by color also
    ;;   User picks objects to determine the color
    ;;   Then User selects objects for ss or presses enter to 
    ;;   get all objects on the selected color
    ;;   You may select the selection set before starting this
    ;;   routine. Then select the layers to keep in the set
    ;;=============================================================
    (defun c:csel (/ ent col colors layers ss col:lst col:prompt ss:first
                   elst filter lay:lst x ent:lst get_layer get_color_name)
      (vl-load-com)
      ;;  return a list of layers using the colors in the list
      ;;  col:lst is a list of color numbers
      (defun get_layer (col:lst / lay lays doc)
        (setq doc (vla-get-activedocument (vlax-get-acad-object)))
        (vlax-for lay (vla-get-layers doc)
          (if (and (member (vla-get-color lay) col:lst)
                   (not (vl-string-search "|" (vla-get-name lay)))
              )
            (setq lays (cons (vla-get-name lay) lays))
          )
        )
        lays
      )
    
      ;; return the color name from the color number supplied
      ;; else return the number as a string
      (defun get_color_name (c# / col)
        (setq col (assoc c# '((1  "Red")
                              (2  "Yellow")
                              (3  "Green")
                              (4  "Cyan")
                              (5  "Blue")
                              (6  "Magenta")
                              (7  "Black/White")
                              (8  "Dark Grey")
                              (9  "Grey"))
                   ))
        (or (cadr col) (itoa c#))
      )
    
      
      ;;  =================================================================
      ;;                       Main Routine                                
      ;;  =================================================================
      ;;  get anything already selected
      (setq ss:first (cadr(ssgetfirst))
            ss (ssadd))
    
      ;;  Get user selected colors
      (if ss:first
        (setq col:prompt "\nSelect the object to choose color to use.")
        (setq col:prompt "\nSelect object for color filter.")
      )
      ;;------------------------------------------------------------------
      (while (setq ent (entsel col:prompt))
        (redraw (car ent) 3) ; highlite the object
        (setq ent:lst (cons (car ent) ent:lst))
        (setq col (cdr(assoc 62 (entget (car ent))))); get the color
        (if (null col) ; color is ByLayer, get layer color
          (setq col (cdr (assoc 62
                                (tblsearch "layer"
                                         (cdr (assoc 8 (entget (car ent))))))))
        )
        (setq col:lst (cons col col:lst))
        (prompt (strcat "\n*-* Selected Color # -> " (get_color_name col)))
      )
      ;;------------------------------------------------------------------
      ;;  Un HighLite the entities
      (and ent:lst (mapcar '(lambda (x) (redraw x 4)) ent:lst))
      (if (> (length col:lst) 0); got color to work with
        (progn
          (setq col:lst (vl-sort col:lst '<)) ; removes douplicates
          (setq colors "" layers "")
          (setq lay:lst (get_layer col:lst)) ; get layers using the colors
          (foreach itm  col:lst ; combine color names into one , del string
            (setq colors (strcat colors (itoa itm) ",")))
          (setq colors (substr colors 1 (1- (strlen colors)))); remove the last ,
          (foreach itm  lay:lst ; combine layer names into one , del string
            (setq layers (strcat layers itm ",")))
          (setq layers (substr layers 1 (1- (strlen layers)))); remove the last ,
          ;;==============================================================
          (if ss:first ; ALREADY GOT SELECTION SET
            (while (setq ent (ssname ss:first 0))
              (setq elst (entget ent))
              (if (or (and (assoc 62 elst) ; got a color
                           (member (abs (cdr(assoc 62 elst))) col:lst)) ; color match
                      (and layers
                           (member (cdr(assoc 8 elst)) lay:lst)
                           (or (null (assoc 62 elst))
                             (= (cdr(assoc 62 elst)) 256)))  ; bylayer
                      )
                (ssadd (ssname ss:first 0) ss)
              )
              (ssdel (ssname ss:first 0) ss:first)
            )
            ;; else get a selection set to work with
            (progn 
              (prompt (strcat "\nOK >>--> Select objects for Selection set or "
                              "ENTER for All objects on color(s) " colors))
              ;;  create the filter
              (if layers
                (setq filter (append
                               (cons '(-4 . "<OR") (mapcar '(lambda (x) (cons 62 x)) col:lst))
                               (list '(-4 . "<AND")
                                     (cons 8 layers)
                                     '(62 . 256) ;  ByLayer
                                     '(-4 . "AND>")
                                     '(-4 . "OR>")
                                    )))
                (setq filter (list (cons 62 colors))) 
              )
              ;;  get objects using filter with user select
              (if (null (setq ss (ssget filter)))
                ;; or get ALL objects using filter
                (setq ss (ssget "_X" filter))
              )
            )
          )
          ;;==============================================================
          (if (> (sslength ss) 0)
            (progn
              (prompt (strcat "\n" (itoa (sslength ss))
                          " Object(s) selected on color(s) " colors
                          "\nStart an ACAD command."))
              (sssetfirst nil ss)
            )
            (prompt "\n***  Nothing Selected  ***")
          )
        )
      )
      (princ)
    )
    (prompt "\nSelect by color loaded, Enter cSel to run.")

  3. #3
    Certifiable AUGI Addict ccowgill's Avatar
    Join Date
    2004-08
    Location
    Iron Station, NC
    Posts
    3,198
    Login to Give a bone
    0

    Default Re: Selection set of polylines that are a specific color

    I'm not to familar with vla commands, is there somewhere that I can get a list of all the functions and what they do?

  4. #4
    Administrator Opie's Avatar
    Join Date
    2002-01
    Location
    jUSt Here (a lot)
    Posts
    9,105
    Login to Give a bone
    0

    Default Re: Selection set of polylines that are a specific color

    The help files will help with a lot of the vlisp commands. You can access it through the Developer's Guide. I think that is the name of it.
    If you have a technical question, please find the appropriate forum and ask it there.
    You will get a quicker response from your fellow AUGI members than if you sent it to me via a PM or email.
    jUSt

  5. #5
    I could stop if I wanted to tyshofner's Avatar
    Join Date
    2004-03
    Location
    Dallas, Tx
    Posts
    229
    Login to Give a bone
    0

    Default Re: Selection set of polylines that are a specific color

    Or if you don't want to use Visual Lisp, this will work (corrected portions in red)

    Code:
     
    (setq co (getstring "\nColor to Add?"))
    (setq SSET (ssget "X" (list (cons 0 "*POLYLINE")(cons 62 (atoi co)))))
    You just needed to convert the color value from a string to an integer, and I added the "X" so that the ssget will select all automatically.

    Ty

  6. #6
    Certifiable AUGI Addict ccowgill's Avatar
    Join Date
    2004-08
    Location
    Iron Station, NC
    Posts
    3,198
    Login to Give a bone
    0

    Default Re: Selection set of polylines that are a specific color

    Quote Originally Posted by tyshofner
    Or if you don't want to use Visual Lisp, this will work (corrected portions in red)

    Code:
     
    (setq co (getstring "\nColor to Add?"))
    (setq SSET (ssget "X" (list (cons 0 "*POLYLINE")(cons 62 (atoi co)))))
    You just needed to convert the color value from a string to an integer, and I added the "X" so that the ssget will select all automatically.

    Ty
    So in other words, if I change GETSTRING to GETINT, it would also take care of it?

  7. #7
    Administrator Opie's Avatar
    Join Date
    2002-01
    Location
    jUSt Here (a lot)
    Posts
    9,105
    Login to Give a bone
    0

    Default Re: Selection set of polylines that are a specific color

    Quote Originally Posted by ccowgill
    So in other words, if I change GETSTRING to GETINT, it would also take care of it?
    And remove the atoi function Ty added.
    If you have a technical question, please find the appropriate forum and ask it there.
    You will get a quicker response from your fellow AUGI members than if you sent it to me via a PM or email.
    jUSt

  8. #8
    All AUGI, all the time CAB2k's Avatar
    Join Date
    2016-01
    Location
    Brandon, Florida
    Posts
    687
    Login to Give a bone
    0

    Default Re: Selection set of polylines that are a specific color

    That will not select objects that are color bylayer where the layer color is
    the color you want also.

  9. #9
    Certifiable AUGI Addict ccowgill's Avatar
    Join Date
    2004-08
    Location
    Iron Station, NC
    Posts
    3,198
    Login to Give a bone
    0

    Default Re: Selection set of polylines that are a specific color

    Thanks for the assistance. the routine gives an option to choose the layer, I just wanted to be able to chose the color in case the Polylines are all on the same layer, just different colors

  10. #10
    All AUGI, all the time CAB2k's Avatar
    Join Date
    2016-01
    Location
    Brandon, Florida
    Posts
    687
    Login to Give a bone
    0

    Default Re: Selection set of polylines that are a specific color

    I see, it's getting more clear as to what you are dealing with.
    The objects will only be "POLYLINE" not "LWPOLYLINE" and a set color or "BYLAYER" color.
    In that case the direction you are headed will work. Sorry for the confusion.

Similar Threads

  1. Drawing selection specific
    By CADKid in forum AutoCAD General
    Replies: 3
    Last Post: 2010-02-15, 07:33 PM
  2. Dim Text on Specific Layer instead of having Specific Color
    By Masroor Javid in forum ACA Wish List
    Replies: 0
    Last Post: 2009-02-23, 09:34 AM
  3. Replies: 0
    Last Post: 2008-03-17, 02:07 AM
  4. Mtext selection color
    By stu1037 in forum AutoCAD General
    Replies: 4
    Last Post: 2005-09-29, 09:48 PM
  5. Selection color
    By rons1800 in forum Revit Architecture - General
    Replies: 2
    Last Post: 2003-09-22, 02:05 PM

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •