Page 1 of 2 12 LastLast
Results 1 to 10 of 13

Thread: Select entities by color of an exploded block

  1. #1
    I could stop if I wanted to
    Join Date
    2001-01
    Posts
    257
    Login to Give a bone
    0

    Default Select entities by color of an exploded block

    Hi All

    What I am trying to do is explode a block and then find all of the entities that were within the block that are in red (1) and create a selection set of them. I have been working with the following snippet of code and I cannot get it to work. Any help is greatly appreciated. Thanks.

    Manuel

    Code:
         (setq entmp (entlast))
         (command ".explode" entmp)
         (setq nsset (ssadd)
                 ent (entnext entmp)
         )
        (while entmp
          (if (= (dxf 62 (entget ent)) 1)
            (setq nsset (ssadd ent nsset)
                    ent (entnext entmp)
                    entmp ent
            
              )
           )
        )

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

    Default Re: Select entities by color of an exploded block

    Are these items set to red based on the layer or are they set to red by object? If they are by layer, then there will not be a group code for 62.

    You would need to get a list of layers that have red assigned to them. Remember, layers that are set to Off have their color assigned as a negative number.

    Once you have this list, you could update your selection set filter to also include those layers.

    Another thing is a successful EXPLODE command creates a new selection set.
    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

  3. #3
    I could stop if I wanted to
    Join Date
    2001-01
    Posts
    257
    Login to Give a bone
    0

    Default Re: Select entities by color of an exploded block

    Opie

    Can I search a select set for all entities on a layer whose color has been changed to red? Thanks.

    Manuel

  4. #4
    All AUGI, all the time
    Join Date
    2010-06
    Posts
    962
    Login to Give a bone
    0

    Default Re: Select entities by color of an exploded block

    Maybe This way ?

    Add your Layer name as shown below .

    Code:
    (setq ss (ssget "_x" '((8 . "YourlayerName")(62 . 1))))

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

    Default Re: Select entities by color of an exploded block

    Tharwat, I don't think that will work. You want to select entities that may have the color changed or have their layer color set to the desired value.

    Manuel, you need to cycle through the layer list and create a list of layers with your desired color. You could do this with a while statement.
    Code:
    (defun LayerListByColor	(ColorNumber / LayerData LayerList)
      (setq LayerList '())
      (while (setq LayerData (tblnext "LAYER" (not LayerData)))
        (if	(= (cdr (assoc 62 LayerData)) ColorNumber)
          (setq
    	LayerList (append LayerList (list (cdr (assoc 2 LayerData))))
          )
        )
      )
      (if (> (length LayerList) 0)
        LayerList
      )
    )
    Once this list is generated, use the layer names and CONStruct an associative list. You can quickly do this with the MAPCAR and LAMBDA functions.
    Code:
    (mapcar '(lambda (x) (cons 8 x)) (layerlistbycolor 1))
    From there you need to add a filter for color and wrap the entire filter with an set of "XOR" filters
    Code:
    (setq filter (list (cons -4 "<XOR")(cons 62 1)(mapcar '(lambda (x) (cons 8 x)) (layerlistbycolor 1))(cons -4 "XOR>")))
    You could then add this to your SSGET function.
    Code:
    (ssget filter)
    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

  6. #6
    I could stop if I wanted to
    Join Date
    2001-01
    Posts
    257
    Login to Give a bone
    0

    Default Re: Select entities by color of an exploded block

    Tharwat

    Thank you for the suggestion. I was able to modify your code to use ssget "_P" and get it to worked.

    Manuel

  7. #7
    I could stop if I wanted to
    Join Date
    2009-03
    Location
    London, England
    Posts
    304
    Login to Give a bone
    0

    Default Re: Select entities by color of an exploded block

    Here is another way to approach it:

    Code:
    (defun c:test ( / blk def ent enx lst rss )
    
      (while (setq def (tblnext "LAYER" (null def)))
        (if (= 1 (abs (cdr (assoc 62 def))))
          (setq lst (cons (cdr (assoc 2 def)) lst))
        )
      )
    
      (if
        (and
          (setq blk (car (entsel "\nSelect Block to Explode: ")))
          (eq "INSERT" (cdr (assoc 0 (entget blk))))
        )
        (progn
          (setq ent (entlast) rss (ssadd))
          (command "_.explode" blk)
          (while (setq ent (entnext ent))
            (setq enx (entget ent))
            (if
              (or (= 1 (cdr (assoc 62 enx)))
                (and
                  (or
                    (not (assoc 62 enx))
                    (= 256 (cdr (assoc 62 enx)))
                  )
                  (member (cdr (assoc 8 enx)) lst)
                )
              )
              (ssadd ent rss)
            )
          )
          (sssetfirst nil rss)
        )
      )
      (princ)
    )

  8. #8
    All AUGI, all the time
    Join Date
    2015-10
    Location
    Belgrade, Serbia, Europe
    Posts
    564
    Login to Give a bone
    0

    Default Re: Select entities by color of an exploded block

    Quote Originally Posted by Opie View Post
    Once this list is generated, use the layer names and CONStruct an associative list. You can quickly do this with the MAPCAR and LAMBDA functions.
    Code:
    (mapcar '(lambda (x) (cons 8 x)) (layerlistbycolor 1))
    From there you need to add a filter for color and wrap the entire filter with an set of "XOR" filters
    Code:
    (setq filter (list (cons -4 "<XOR")(cons 62 1)(mapcar '(lambda (x) (cons 8 x)) (layerlistbycolor 1))(cons -4 "XOR>")))
    Opie, I here don't understand something...

    (mapcar '(lambda (x) (cons 8 x)) (layerlistbycolor 1))
    This is behaving as one operand, in "XOR" filter condition, or is it as I suspect list of more operands with dotted pair (8 . "Layername")...

    Here is written that "XOR" filter condition accepts only 2 operands and ssget makes selection if ether first operand filter condition is T, or either second operand condition is T...

    If my suspection is correct, shouldn't condition be "OR", but not "XOR"...

    M.R.

  9. #9
    All AUGI, all the time
    Join Date
    2015-10
    Location
    Belgrade, Serbia, Europe
    Posts
    564
    Login to Give a bone
    0

    Default Re: Select entities by color of an exploded block

    I think Opie, you should try this code (with "OR" it works - selects all red objects either by object color or by red Layers with objects in them, but with "XOR" it doesn't select anything)...

    Code:
    (defun LayerListByColor (ColorNumber / LayerData LayerList)
      (setq LayerList '())
      (while (setq LayerData (tblnext "LAYER" (not LayerData)))
        (if	(= (cdr (assoc 62 LayerData)) ColorNumber)
          (setq
    	LayerList (append LayerList (list (cdr (assoc 2 LayerData))))
          )
        )
      )
      (if (> (length LayerList) 0)
        LayerList
      )
    )
    
    (defun c:ssf (/ ss filter)
    (setq filter (cons (cons -4 "<OR")(cons (cons 62 1)(mapcar '(lambda (x) (cons 8 x)) (layerlistbycolor 1)))))
    (setq filter (reverse filter))
    (setq filter (cons (cons -4 "OR>") filter))
    (setq filter (reverse filter))
    (setq ss (ssget "X" filter))
    (sssetfirst nil ss)
    (princ)
    )
    M.R.

    P.S. Try with XOR and see for yourself...

    This variant of code has XOR filter condition and is in conjunction with AND condition - this will select all objects in red color only if 1 Layer with red color exist; if there are more than 1 Layer with red color it will select only objects that have red color property and don't belong to any of layers that are red...

    Code:
    (defun LayerListByColor (ColorNumber / LayerData LayerList)
      (setq LayerList '())
      (while (setq LayerData (tblnext "LAYER" (not LayerData)))
        (if	(= (cdr (assoc 62 LayerData)) ColorNumber)
          (setq
    	LayerList (append LayerList (list (cdr (assoc 2 LayerData))))
          )
        )
      )
      (if (> (length LayerList) 0)
        LayerList
      )
    )
    
    (defun c:ssf (/ ss filter)
    (setq filter (cons (cons -4 "<AND") (mapcar '(lambda (x) (cons 8 x)) (layerlistbycolor 1)) ))
    (setq filter (reverse filter))
    (setq filter (cons (cons -4 "AND>") filter))
    (setq filter (reverse filter))
    (setq filter (cons (cons -4 "<XOR")(cons (cons 62 1) filter)))
    (setq filter (reverse filter))
    (setq filter (cons (cons -4 "XOR>") filter))
    (setq filter (reverse filter))
    (setq ss (ssget "X" filter))
    (sssetfirst nil ss)
    (princ)
    )
    M.R.
    Last edited by marko_ribar; 2011-06-26 at 05:18 PM. Reason: added additional code with XOR and AND condition filters

  10. #10
    All AUGI, all the time
    Join Date
    2015-10
    Location
    Belgrade, Serbia, Europe
    Posts
    564
    Login to Give a bone
    0

    Default Re: Select entities by color of an exploded block

    Does anyone know why (read) function here reads only first part of string - first dotted pair

    Code:
    (defun LayerListByColor	(ColorNumber / LayerData LayerList)
      (setq LayerList '())
      (while (setq LayerData (tblnext "LAYER" (not LayerData)))
        (if	(= (cdr (assoc 62 LayerData)) ColorNumber)
          (setq
    	LayerList (append LayerList (list (cdr (assoc 2 LayerData))))
          )
        )
      )
      (if (> (length LayerList) 0)
        LayerList
      )
    )
    
    (defun c:ssf (/ ss llbc llbcn llbcnlen filter)
    (setq llbc (mapcar '(lambda (x) (cons 8 x)) (layerlistbycolor 1)))
    (setq llbcn (vl-prin1-to-string llbc))
    (setq llbcnlen (strlen llbcn))
    (setq llbcn (substr llbcn 2 (- llbcnlen 2)))
    (setq filter (list (cons -4 "<OR")(cons 62 1)(read llbcn)(cons -4 "OR>")))
    (setq ss (ssget "X" filter))
    (sssetfirst nil ss)
    (princ)
    )
    M.R.
    Thanks if replied...

Page 1 of 2 12 LastLast

Similar Threads

  1. Select entities off the screen
    By bweir in forum AutoLISP
    Replies: 5
    Last Post: 2007-04-20, 09:14 PM
  2. Can't select entities
    By jpaulsen in forum AutoCAD General
    Replies: 6
    Last Post: 2007-04-19, 03:20 PM
  3. Replies: 18
    Last Post: 2005-10-28, 12:18 AM
  4. Select entities without touching them
    By autocad.wishlist1734 in forum AutoCAD Wish List
    Replies: 0
    Last Post: 2005-10-05, 12:22 PM
  5. Changing block entities' color to bylayer
    By sifuentes in forum AutoCAD General
    Replies: 20
    Last Post: 2004-11-12, 04:44 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
  •