Jump to content

Create secondary Selection Sets from first Selection Set...


lamensterms

Recommended Posts

Hey guys,

 

Just wondering a way to create 2 secondary selection sets from 1 primary one.

 

My situation is.. i want to be able to select a bunch of lines/arcs/elipses/etc which will be one 1 of two layers (layers name 1H and 5C).

 

The entities on layer 1H i wish to erase and the entities on layer 5C i wish to colour yellow.

 

I dont have an example code or anything - it is at work. I was just hoping someone could let me know how to use 'Selection Set 1' to create 'Selection Set 2' and 'Selection Set 3'. I know which filters I need... just not how to apply them twice to the first Selection Set.

 

Thanks for any help.

Link to comment
Share on other sites

Hi .

 

After you have collected a selection set you can step through it for a specific conditions you want , by Layers , Entities ... etc

 

- Make an empty selection set like this ( setq s (ssadd))

- Step through you first selection set , and when it match your criteria , add that entity name to the new selection set which is s in our first step

like this (ssadd s)

- At the end you would have a new selection set of your desire conditions if your criteria found with the selection set entity name .

 

Good luck.

 

Tharwat

Link to comment
Share on other sites

Since there are no common processing(s) for the two groups, is better to build two selection sets. This way will have a much simple code and the processing will be faster, too.

(ssget "_X" '((0 . "LINE,ARC,ELLIPSE") (8 . "1H")))   ;1st selection set
(ssget "_X" '((0 . "LINE,ARC,ELLIPSE") (8 . "5C")))   ;2nd selection set

Link to comment
Share on other sites

Since there are no common processing(s) for the two groups, is better to build two selection sets. This way will have a much simple code and the processing will be faster, too.

(ssget "_X" '((0 . "LINE,ARC,ELLIPSE") (8 . "1H")))   ;1st selection set
(ssget "_X" '((0 . "LINE,ARC,ELLIPSE") (8 . "5C")))   ;2nd selection set

 

This method would be suitable providing that the OP wishes to operate on all of the objects on each of the respective layers.

 

Should the OP wish to manually select a number of objects on each layer, I would restrict the initial set to only permit objects on either layer "1H" or "5C", then use an if statement whilst iterating over the set to determine how each object should be processed based on its layer.

 

Also, note that by collecting two selection sets using the "_X" mode string, the entire drawing database is being traversed twice to retrieve the sets, which are then processed separately.

 

For this particular situation, I would be inclined to use something like:

 

(if (setq s (ssget "_:L" '((0 . "LINE,ARC,ELLIPSE") (8 . "1H,5C"))))
   (repeat (setq i (sslength s))
       (setq e (ssname s (setq i (1- i)))
             l (entget e)
       )
       (if (= "1H" (cdr (assoc 8 l)))
           <do something>
           <do something else>
       )
   )
)

Link to comment
Share on other sites

Since that you would use the same selection set for the same purpose , you should just step through the of each selection set .

 

e.g.

 

(if (setq ss (ssget "_:L" '((0 . "LINE,ARC,ELLIPSE")(8 . "1H,5C"))))
 (repeat (setq i (sslength ss))
   (setq sn (ssname ss (setq i (1- i))))
   (setq l (cdr (assoc 8 (setq e (entget sn)))))
   (cond ((eq l "H1") (entdel sn))
         ((eq l "5C")
          (if (cdr (assoc 62 e))
            (entmod (subst (cons 62 2) (assoc 62 e) e))
            (entmod (append e (list (cons 62 2))))
          )
         )
   )
 )
 (princ)
)

Link to comment
Share on other sites

Hi guys,

 

Thanks so much for your fast replies.

 

Tharwat - I managed to get your routine to do exactly what I need (i think). The code is a little too sophisticated for me to understand, but it does work so thank you for that.

 

Thanks as well Lee, I couldnt figure out how to apply the actions to your code. I've still got so much to learn with LISP - but I'm finding less and less time to study it.

 

Thanks again everyone.

 

(DEFUN C:TEST ()
(if (setq ss (ssget "_:L" '((0 . "LINE,ARC,ELLIPSE")(8 . "1H,5C"))))
 (repeat (setq i (sslength ss))
   (setq sn (ssname ss (setq i (1- i))))
   (setq l (cdr (assoc 8 (setq e (entget sn)))))
   (cond ((eq l "1H") (entdel sn))
         ((eq l "5C")
          (if (cdr (assoc 62 e))
            (entmod (subst (cons 62 2) (assoc 62 e) e))
            (entmod (append e (list (cons 62 2))))
          )
         )
   )
 )
 (princ)
)
)

 

.... Just for reference.

Link to comment
Share on other sites

Hi guys,

 

Tharwat - I managed to get your routine to do exactly what I need (i think). The code is a little too sophisticated for me to understand, but it does work so thank you for that.

 

(DEFUN C:TEST [color=red][b](/ ss i sn l e)[/b][/color]

 

 

You 're welcome ,

 

you should localize your variables as modified above . :)

Link to comment
Share on other sites

You're welcome.

 

Since there are only two cases (1H or 5C), I think an if statement is more suited (and more readable) over the cond, and the code could be shortened to:

 

(defun c:doit ( / e i l s )
   (if (setq s (ssget "_:L" '((0 . "LINE,ARC,ELLIPSE") (8 . "1H,5C"))))
       (repeat (setq i (sslength s))
           (setq e (ssname s (setq i (1- i)))
                 l (entget e)
           )
           (if (= "1H" (cdr (assoc 8 l)))
               (entdel e)
               (entmod (append l '((62 . 2))))
           )
       )
   )
   (princ)
)

Or, if you like to nest the expressions:

 

(defun c:doit ( / e i l s )
   (if (setq s (ssget "_:L" '((0 . "LINE,ARC,ELLIPSE") (8 . "1H,5C"))))
       (repeat (setq i (sslength s))
           (if (= "1H" (cdr (assoc 8 (setq l (entget (setq e (ssname s (setq i (1- i)))))))))
               (entdel e)
               (entmod (append l '((62 . 2))))
           )
       )
   )
   (princ)
)

Link to comment
Share on other sites

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.
Note: Your post will require moderator approval before it will be visible.

Guest
Unfortunately, your content contains terms that we do not allow. Please edit your content to remove the highlighted words below.
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...