Visual LISP, AutoLISP and General Customization
cancel
Showing results for 
Show  only  | Search instead for 
Did you mean: 

How to verify empty selection in (SSGET)

6 REPLIES 6
SOLVED
Reply
Message 1 of 7
arperezinf
812 Views, 6 Replies

How to verify empty selection in (SSGET)

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.

Labels (1)
6 REPLIES 6
Message 2 of 7
ВeekeeCZ
in reply to: arperezinf

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
in reply to: arperezinf


@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
in reply to: arperezinf

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.

Message 5 of 7
arperezinf
in reply to: arperezinf

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.

Message 6 of 7
Sea-Haven
in reply to: arperezinf

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
in reply to: Sea-Haven

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

Can't find what you're looking for? Ask the community or share your knowledge.

Post to forums  

Forma Design Contest


Autodesk Design & Make Report