Empty selection set - how to process (sslenght ...)?

Empty selection set - how to process (sslenght ...)?

jlc.pub
Enthusiast Enthusiast
1,911 Views
5 Replies
Message 1 of 6

Empty selection set - how to process (sslenght ...)?

jlc.pub
Enthusiast
Enthusiast

Hi,

 

 

I'm trying to do a very simple lisp which ask the user which layer he wants to clean and delete all items on it.

The layer selected by the user is named "folasup" and I make a selection set by :

 

(setq sel (ssget "x" (list (cons '8 Folasup))))

 

Then I try this condition :

(if (> (sslength sel) 0)

My problem is when there is nothing in the selection set... in this case the watch shows me that the content of "sslength sel" is <***ERROR***>.

 

I don't know how to consider this case.

 

Could you help me please ?

0 Likes
Accepted solutions (2)
1,912 Views
5 Replies
Replies (5)
Message 2 of 6

cadffm
Consultant
Consultant
Accepted solution

(If (setq sel (ssget "x" (list (cons '8 Folasup))))

(Progn Mystuff)

)

 

 

OR

 

(And

(setq sel (ssget "x" (list (cons '8 Folasup))))

(Mystuff)

)

Sebastian

0 Likes
Message 3 of 6

ronjonp
Mentor
Mentor
Accepted solution

Here's another:

(if (setq sel (ssget "_X" '((8 . "Folasup"))))
  (foreach x (mapcar 'cadr (ssnamex sel)) (entdel x))
)
0 Likes
Message 4 of 6

dlanorh
Advisor
Advisor

@jlc.pub wrote:

Hi,

 

 

I'm trying to do a very simple lisp which ask the user which layer he wants to clean and delete all items on it.

The layer selected by the user is named "folasup" and I make a selection set by :

 

(setq sel (ssget "x" (list (cons '8 Folasup))))

 

Then I try this condition :

(if (> (sslength sel) 0)

My problem is when there is nothing in the selection set... in this case the watch shows me that the content of "sslength sel" is <***ERROR***>.

 

I don't know how to consider this case.

 

Could you help me please ?


(setq sel (ssget ....))

(if sel
  (progn
    ;process selection set
  );end_progn
  (progn
    (alert "Nothing Selected") or whatever
  );end_progn
);end_if

 

or

 

(setq sel (ssget ....))

(cond (sel
        ;process selection set
       )
       (t
         (alert "Nothing Selected") or whatever
        )
);end_cond

 

I am not one of the robots you're looking for

0 Likes
Message 5 of 6

jlc.pub
Enthusiast
Enthusiast

So fast !

Thanks for your quick reply ! I've tried the first method, it's work perfectly 😁

 

Thanks

0 Likes
Message 6 of 6

ВeekeeCZ
Consultant
Consultant

@jlc.pub wrote:

...

(setq sel (ssget "x" (list (cons '8 Folasup))))

Then I try this condition :

(if (> (sslength sel) 0)

My problem is when there is nothing in the selection set... in this case the watch shows me that the content of "sslength sel" is <***ERROR***>.

..


 

This is bad wording. Your issue isn't "nothing in the ss". It would imply that ss exists but it's empty. But in your case, ss simply does not exist. If comes to selection sets, its really important to understand the difference whether it exists or not and if yes, then whether is empty or not.

 

If you do something like this: (setq ss (ssadd)) 

Now ss is an empty selection set. It means 

- it exists.... (not ss) returns nil

- but it's empty.... (sslength ss) returns 0.

 

HTH

0 Likes