Jump to content

lisp: no items in selection


markschu

Recommended Posts

Hello,

 

I'm new here!

 

I'm trying to make a lisp-routine to get only layers M01, P B99 in a selectionset. I would to have a announcement that says that there is nothing selected when M01, P en B99 are not in the selection

 

This is what i've made: (which is not making the announcement)

 

(defun c:4 ()
(princ "\n Selecteer M01, P en B99")
 (ssget)
  (if (setq myFilter(list (cons 8 "M01,P,B99")))
   (progn
    (ssget "P" myFilter)
   )
  (alert "\nNothing in Selectionset!")    
) 
(princ)
)

Thank you for answering,

 

Mark

Link to comment
Share on other sites

Ah, I was confused for a bit but I see what happened.

 

Here's a hint: setting a variable equal to a list will -always- return True, which means, the "true" part of the IF statement will always occur, no matter what.

Link to comment
Share on other sites

Maybe like this:

 

 

(defun c:4 ()
 (princ "\n Selecteer M01, P en B99")
 (if (not (setq ss (ssget (list (cons 8 "M01,P,B99")))))
     (alert "\nNothing in Selectionset!")) 
 (princ)
)

 

-David

Link to comment
Share on other sites

You replied very quickly. Thank you,

 

@freefill I'm not fully understanding what you are saying but I understand that I cannot use If when I use list.

 

@David: You are making really something else of it. It works, but I could never rebuild it.

Link to comment
Share on other sites

@freefill I'm not fully understanding what you are saying but I understand that I cannot use If when I use list.

 

What Freerefill is pointing out is that your IF statement is always going to return TRUE, as you are always going to be able to set the list to the variable "MyFilter"., Hence this is never going to return NIL, even if the selection set is NIL.

 

@David: You are making really something else of it. It works, but I could never rebuild it.

 

David really hasn't done much more than you already had to be honest. - You had created your filter list, you just had to use it with your initial "ssget" call :)

 

Hope this helps,

 

Lee

Link to comment
Share on other sites

In a nutshell, if you set some variable equal to some value, that variable now has a value. Seems simple enough. Here's something to try: type !blah at the command line, you should see a "nil" pop up (assuming you haven't set "blah" to anything). This is because that variable has no assigned value. If you then type:

 

(setq blah "hello, world")

 

then type !blah, you'll see "hello, world" appear. This is because that variable now has a value.

 

When doing any sort of true/false check, like using a while loop, an if statement, or the and/or statements, you're checking not for a specific value, but overall, true or false (or, perhaps more specifically, true or nil).

 

So lets see that in action.

 

First, test this bit of code:

 

!varvar

 

This should return nil. So if we then do this:

 

(if varvar (princ "True") (princ "False"))

 

We know 'varvar' is nil, so we know we'll see "False" printed. Now lets do this:

 

(setq varvar T)

 

And check that If statement again. It'll return "True", because varvar is true.

 

Now, try these:

 

(setq varvar 1)
(setq varvar 5.0)
(setq varvar "variable")
(setq varvar (list 1 2 3))

 

You'll see that as long as varvar has a value associated with it, the If statement will see it as 'true' and it will print "True".

 

That was your problem: you set a variable equal to something, gave it a defined value, and the checked to see if that value existed. It always exists. What you need to do is not check to see whether or not the list which defines your filter exists, but to see if your selection set has found anything.

 

Does that help to clear things up?

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