乐筑天下

搜索
欢迎各位开发者和用户入驻本平台 尊重版权,从我做起,拒绝盗版,拒绝倒卖 签到、发布资源、邀请好友注册,可以获得银币 请注意保管好自己的密码,避免账户资金被盗
查看: 85|回复: 5

[编程交流] lisp: no items in selection

[复制链接]

1

主题

2

帖子

1

银币

初来乍到

Rank: 1

铜币
5
发表于 2022-7-6 14:19:34 | 显示全部楼层 |阅读模式
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)
 
  1. (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
回复

使用道具 举报

20

主题

344

帖子

325

银币

初露锋芒

Rank: 3Rank: 3Rank: 3

铜币
100
发表于 2022-7-6 14:40:01 | 显示全部楼层
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.
回复

使用道具 举报

26

主题

1495

帖子

20

银币

初露锋芒

Rank: 3Rank: 3Rank: 3

铜币
118
发表于 2022-7-6 14:52:20 | 显示全部楼层
Maybe like this:
 
 
  1. (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
回复

使用道具 举报

1

主题

2

帖子

1

银币

初来乍到

Rank: 1

铜币
5
发表于 2022-7-6 15:02:42 | 显示全部楼层
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.
回复

使用道具 举报

114

主题

1万

帖子

1万

银币

中流砥柱

Rank: 25

铜币
543
发表于 2022-7-6 15:07:44 | 显示全部楼层
 
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 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
回复

使用道具 举报

20

主题

344

帖子

325

银币

初露锋芒

Rank: 3Rank: 3Rank: 3

铜币
100
发表于 2022-7-6 15:28:57 | 显示全部楼层
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:
 
  1. (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:
 
  1. !varvar
 
This should return nil. So if we then do this:
 
  1. (if varvar (princ "True") (princ "False"))
 
We know 'varvar' is nil, so we know we'll see "False" printed. Now lets do this:
 
  1. (setq varvar T)
 
And check that If statement again. It'll return "True", because varvar is true.
 
Now, try these:
 
  1. (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?
回复

使用道具 举报

发表回复

您需要登录后才可以回帖 登录 | 立即注册

本版积分规则

  • 微信公众平台

  • 扫描访问手机版

  • 点击图片下载手机App

QQ|关于我们|小黑屋|乐筑天下 繁体中文

GMT+8, 2025-3-5 03:14 , Processed in 0.971651 second(s), 64 queries .

© 2020-2025 乐筑天下

联系客服 关注微信 帮助中心 下载APP 返回顶部 返回列表