乐筑天下

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

[编程交流] Understanding AutoLISP - a pro

[复制链接]

15

主题

243

帖子

228

银币

初露锋芒

Rank: 3Rank: 3Rank: 3

铜币
75
发表于 2022-7-6 00:41:59 | 显示全部楼层
Oh once again Lee has made this, alright!
回复

使用道具 举报

15

主题

243

帖子

228

银币

初露锋芒

Rank: 3Rank: 3Rank: 3

铜币
75
发表于 2022-7-6 00:47:46 | 显示全部楼层
In browsing the forums today, I came upon an issue that i'd like to post back into this thread. Revitalize it just a little bit...
I'm attempting to use the (member) function to check if an item (string) belongs to a list of strings.
All I'm getting is Nil....here are the conditions.
  1. (setq lst (dynamicpropertyallowedvalues (car (entsel)) "*"))Select object: (("Visibility1" "Check Valve" "Flanged Check Valve"))Command: !lst(("Visibility1" "Check Valve" "Flanged Check Valve"))
 
So that's what I've done to obtain my list, that's a subfunction that is defined elsewhere. Now, when I try to see if a string "Check Valve" is contained within lst, which it obviously is....
  1. Command: (member '"Check Valve" lst)nilCommand: (member "check valve" lst)nilCommand: (member "Visibility1" lst)nilCommand: (setq theitem "Flanged Check Valve")"Flanged Check Valve"Command: (member theitem lst)nil
 
So that's where I'm at, hoping to gain some understanding as to why my member function isn't returning True or returning a list with the given member item and the following items...
If I'm going about this the wrong way, could someone please inform me as to the proper way to check if a string is contained within a list and how to manipulate it. The lst length should vary, under these conditions I do not want to use (nth) or similar functions because those would not work for what i'm trying to do.
Thanks in advance!
回复

使用道具 举报

114

主题

1万

帖子

1万

银币

中流砥柱

Rank: 25

铜币
543
发表于 2022-7-6 00:52:18 | 显示全部楼层
You have a list within a list:
 
  1. _$ (setq lst '(("Visibility1" "Check Valve" "Flanged Check Valve")))(("Visibility1" "Check Valve" "Flanged Check Valve"))_$ (member '("Visibility1" "Check Valve" "Flanged Check Valve") lst)(("Visibility1" "Check Valve" "Flanged Check Valve"))_$ (member "Visibility1" (car lst))("Visibility1" "Check Valve" "Flanged Check Valve")_$ (member "Check Valve" (car lst))("Check Valve" "Flanged Check Valve")
回复

使用道具 举报

15

主题

243

帖子

228

银币

初露锋芒

Rank: 3Rank: 3Rank: 3

铜币
75
发表于 2022-7-6 00:52:54 | 显示全部楼层
Okay, great, that should do....thanks, I'll test it too but I see from your returned info there what needs to happen.
Thanks Lee, once again
 
 
Ahhhhh, alright. I see.
  1. (member "Visibility1" (car lst))("Visibility1" "Check Valve" "Flanged Check Valve")
 
How I would have expected my tests earlier to return is obtained by this method, simply stating adding to look in the first item in the list "lst" , being as there is only the one actual list with data within lst, that's why the (car) function is required. And once it's looking at the lst containing the three strings, and finds "Visibility1" within that list, it returns the entire list.
 
It does not, however, return True...but I'm assuming that an (if) statement could be wrapped around the (member) statement and if a list is returned (i.e. the item is found in the list), then the if function would proceed to the "then" portion, as if it returned True. This would be easy to test in fact i'll do it now....
回复

使用道具 举报

114

主题

1万

帖子

1万

银币

中流砥柱

Rank: 25

铜币
543
发表于 2022-7-6 00:58:36 | 显示全部楼层
 
Note that this is only because "Visibility1" is the first item in the list supplied to member.
回复

使用道具 举报

15

主题

243

帖子

228

银币

初露锋芒

Rank: 3Rank: 3Rank: 3

铜币
75
发表于 2022-7-6 01:01:47 | 显示全部楼层
Similar to the (cdr) function in that regard, if I had given it "Check Valve" it would return just the 2.......
as shown in your last example.
And similarly
  1. Command: (setq lst '(("Visibility1" "Check Valve" "Flanged Check Valve")))(("Visibility1" "Check Valve" "Flanged Check Valve"))Command: (member "Flanged Check Valve" (car lst))("Flanged Check Valve")
 
Okay, got it. Thanks again!
回复

使用道具 举报

发表回复

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

本版积分规则

  • 微信公众平台

  • 扫描访问手机版

  • 点击图片下载手机App

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

GMT+8, 2025-3-10 21:27 , Processed in 0.564008 second(s), 62 queries .

© 2020-2025 乐筑天下

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