How to verify empty selection in (SSGET)

How to verify empty selection in (SSGET)

arperezinf
Advocate Advocate
1,809 Views
6 Replies
Message 1 of 7

How to verify empty selection in (SSGET)

arperezinf
Advocate
Advocate

Hello 👋 

 

I have a problem with my routine lisp code, it gives me an error when I have no element selected and I press the enter key.

 

I would like to know how I can make it check if the selection is empty in (ssget) and if it is, repeat (ssget), until there is a selection or the routine is canceled.

 

I wanted to use an if statement, but I didn't know where to put the statement.

 

This is the code

(setq linkvalue (itoa value)
  ss      (ssget)
  len     (sslength ss)
  cont     0
  entdata  linkvalue
)

Thank you very much for reading my message.
Greetings.

0 Likes
Accepted solutions (1)
1,810 Views
6 Replies
Replies (6)
Message 2 of 7

ВeekeeCZ
Consultant
Consultant

where do you get a "value" from?

are you selecting texts to set "linkvalue" as their contents?

 

here is an example:

 

 

  (if (setq ss (ssget))
    
    (repeat (setq index (sslength ss))
      (setq entname (ssname ss (setq index (1- index))))
      (setq entdata (entget entname))
      (... do something ...)
      
      ) ; end of repeat
    ) ; end of if

 

Message 3 of 7

Kent1Cooper
Consultant
Consultant
Accepted solution

@arperezinf wrote:

.... I would like to know how I can make it check if the selection is empty in (ssget) and if it is, repeat (ssget), until there is a selection or the routine is canceled.

.....


(setq linkvalue (itoa value))

(while (not (setq ss (ssget))))

(setq len (sslength ss) ....

Kent Cooper, AIA
Message 4 of 7

arperezinf
Advocate
Advocate

Hello 👋 @ВeekeeCZ @Kent1Cooper 

 

Thank you very much for your comments.


I ask for the value in another line of code before this part of code that I do not publish and I am using (getint), an integer and I am selecting blocks.

 

Let me analyze how I implement what they say in my code because I don't know much about visual lisp programming.

 

Thank you very much for reading my message.
Greetings.

0 Likes
Message 5 of 7

arperezinf
Advocate
Advocate

Hello 👋 @ВeekeeCZ @Kent1Cooper 

Thank you very much to both.🤝

I already managed to do what I needed!😀👌
@Kent1Cooper your code works as I need, it is the solution I was looking for.👏🙏🤝👍

Thank you very much for reading my message.
Greetings.

0 Likes
Message 6 of 7

Sea-Haven
Mentor
Mentor

Like Kent's answer I often use an alert to show ssget failed.

 

(if (=(setq ss (ssget)) nil)
(alert "There is no selection set please run again")
(repeat (setq index (sslength ss))

The other is a hard exit but have to be careful does not cause problems.
(if (=(setq ss (ssget)) nil)
  (progn
    (alert "There is no selection set please run again\nWill now exit")
    (exit)
  )
(repeat (setq index (sslength ss))
Message 7 of 7

arperezinf
Advocate
Advocate
Thank you very much for your comment, I will keep it in mind.
Greetings.
0 Likes