Jump to content

How to apply filters to a selection set created by (ssadd)?


vanowm

Recommended Posts

Hello.

 

I probably missing something obvious here, but how do I apply filters with SSGET to different selection sets (created with SSADD)?

 

Just a quick and crude example which doesn't work (obviously):

; ss1 and ss2 are two different selection sets. How they were created is irrelevant.
(print (sslength ss1))

;apply filter to ss1 selection set
;(setq ss1 (ssget ss1 '((8 . "Layer2"))))

(print (sslength ss1))

in this example ss1 and ss2 are two different selection sets (how they were created is irrelevant), and I'm looking for a way apply a filter on them if possible without going through each entity in the set separately unless it's most optimized solution.

 

Thank you.

Edited by vanowm
Dumbing down the example, because evidently making an usable example makes it too confusing for some people...
Link to comment
Share on other sites

I think this is what you want

 

(setq ss1 (ssget "X" '((0 . "LINE")(8 . "Layer2")))

or you can make a new selection set by using ssadd but checking if the (assoc 8 "Layer2") is true for each item in ss1

Link to comment
Share on other sites

Are you after cycling through the already created selection set to check if any object in the fore-said selection set is matching a specific name of layer then create a new selection set ?

Link to comment
Share on other sites

No, not really, I was trying avoid looping through the set.

 

So far the only solution I could come up that doesn't require loop through the set is to use SSSETFIRST:

; ss1 and ss2 are two different selection sets. How they were created is irrelevant.

(print (sslength ss1)) ;number of entities before the filter

(setq ss_orig (ssget "_I")) ; save original selection
(sssetfirst nil ss1) ;force selection with new set
(setq ss1 (ssget "_I" '((8 . "Layer2")))) ;apply the filter

(print (sslength ss1)) ;number of entities after the filter

(if ss_orig
   (sssetfirst nil ss_orig) ;restore original selection
)

I don't know if this is most efficient way of doing it though.

Edited by vanowm
Link to comment
Share on other sites

No, not really, I was trying avoid looping through the set.

 

So far the only solution I could come up that doesn't require loop through the set is to use SSSETFIRST:

I don't know if this is most efficient way of doing it though.

 

BIGAL's code looked a lot simpler to me.

Link to comment
Share on other sites

BIGAL's code looked a lot simpler to me.

 

Yes, it does, if you totally disregard my original post, such as using "X" mode will filter through every single entity in the drawing, but I need apply the filter to only specific set of entities.

Link to comment
Share on other sites

Yes, it does, if you totally disregard my original post, such as using "X" mode will filter through every single entity in the drawing, but I need apply the filter to only specific set of entities.

But that's exactly the same thing you're doing.

(setq ss1 (ssget "X" '((0 . "LINE")))

He just combined the filters for you.

 

If you put the entire code up or just what you want the code to do it we would be better able to provide answers.

Link to comment
Share on other sites

in this example I'm using "X" to create selection sets, but in my script these sets are custom created via SSADD therefore I cannot use filters before/during selection set is created, I need apply them AFTER selection set is created.

 

Yes, it does, if you totally disregard my original post

I rest my case.

Link to comment
Share on other sites

I rest my case.

You posted no code using SSADD providing a more "efficient way of doing it" requires actually being able to see how you're doing it now.

So again: "If you put the entire code up or just what you want the code to do it we would be better able to provide answers. "

Link to comment
Share on other sites

Yes, it does, if you totally disregard my original post, such as using "X" mode will filter through every single entity in the drawing, but I need apply the filter to only specific set of entities.

 

I believe this is what you want. To filter lines on a specific layer and circle. Remove the "_x" if you want to select manually.

 

(setq ss 
 (ssget "_x"
  '(
     (-4 . "<OR")
       (-4 . "<AND") (0 . "LINE") (8 . "Layer2")  (-4 . "AND>")
       (-4 . "<AND") (0 . "CIRCLE") (-4 . "AND>")
     (-4 . "OR>")
   )
 )
)

Link to comment
Share on other sites

       [color=magenta](-4 . "<AND")[/color] (0 . "CIRCLE")[color=magenta] (-4 . "AND>")[/color]
     

 

I think there is no need for the two DXFs and since you have only one name of entity and without any further DXF filters.

Link to comment
Share on other sites

I think there is no need for the two DXFs and since you have only one name of entity and without any further DXF filters.

 

At first that was my initial code, since OP is not used with logical operator on ssget it wouldn't hurt to add the "and" operand so he can filter the circle further if he want to.

Link to comment
Share on other sites

I've updated original post. I hope it clears things up better.

 

And I'll repeat myself one more time: (SSGET "_X") will not work, because it will apply to all entities in the drawing, and not to specific entities in the already defined selection set.

Link to comment
Share on other sites

I've updated original post. I hope it clears things up better.

 

And I'll repeat myself one more time: (SSGET "_X") will not work, because it will apply to all entities in the drawing, and not to specific entities in the already defined selection set.

 

here, filter ss1 with layer.

 

(filter-ss ss1 "Layer2")

 

(defun filter-ss ( ss1 lay / i lst )
 (repeat (setq i (sslength ss1))
   (if
     (not 
       (= 
         lay 
         (cdr 
           (assoc 8 
             (entget 
               (setq e 
                 (ssname ss1 
                   (setq i (1- i))
                 )
               )
             )
           )
         )
       )
     )
     (setq lst (cons e lst))
   ) 
 )
 (mapcar 
   (function 
     (lambda (a) 
       (ssdel a ss1)
     )
   ) lst
 ) 
)
 

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...