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.
Solved! Go to Solution.
Solved by Kent1Cooper. Go to Solution.
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
@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) ....
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.
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.
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))
Can't find what you're looking for? Ask the community or share your knowledge.