乐筑天下

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

[编程交流] How to check whether entity�

[复制链接]

26

主题

84

帖子

58

银币

初露锋芒

Rank: 3Rank: 3Rank: 3

铜币
130
发表于 2022-7-5 16:26:07 | 显示全部楼层 |阅读模式
Hi all,
 
I am getting error: bad argument type: lentityp by running following code:
 
  1. (defun ATR ( handSTR)  (if (HANDENT handSTR)   (progn     (setq ss1 (ssadd handSTR))     (command ".attedit" "y" "*" "*" "*" ss1 "color" "t" "255,0,0" "n")     (ssdel handSTR ss1)   ) ) (princ))(ATR "543B")
 
What am I doing wrong here?
回复

使用道具 举报

66

主题

1552

帖子

1514

银币

后起之秀

Rank: 20Rank: 20Rank: 20Rank: 20

铜币
325
发表于 2022-7-5 16:39:23 | 显示全部楼层
  1. _$ (handent nil)Error: bad argument type: stringp nil_1$
 
So use:
  1. (and (eq 'STR (type handent)) (handent handSTR))
 
instead of:
  1. (HANDENT handSTR)
 
EDIT: Oh, and the actual reason for the error:
Change:
  1. (setq ss1 (ssadd handSTR))
To:
  1. (setq ss1 (ssadd (handent handSTR)))
回复

举报

114

主题

1万

帖子

1万

银币

中流砥柱

Rank: 25

铜币
543
发表于 2022-7-5 16:47:31 | 显示全部楼层
I would also suggest testing whether (entget (handent )) returns a non-nil value (i.e. testing whether the entity is erased), as handent can return the entity name for entities for which the erase flag is set.
回复

举报

18

主题

1529

帖子

973

银币

中流砥柱

Rank: 25

铜币
649
发表于 2022-7-5 16:55:59 | 显示全部楼层
... Or use vlax-erased-p (faster than entget).
回复

举报

66

主题

1552

帖子

1514

银币

后起之秀

Rank: 20Rank: 20Rank: 20Rank: 20

铜币
325
发表于 2022-7-5 17:05:46 | 显示全部楼层
I also think that it would be good to include this part to the checklist (wrapped within and function):
  1. (setq ss1 (ssadd (handent handSTR)))
And use progn for the command call and ssdel.
To account non-graphical entity's handles:
  1. _$ (ssadd (handent (cdr (assoc 5 (entget (namedobjdict))))))nil
 
回复

举报

18

主题

1529

帖子

973

银币

中流砥柱

Rank: 25

铜币
649
发表于 2022-7-5 17:13:57 | 显示全部楼层
@Grrr:
  1. (equal (namedobjdict) (handent (cdr (assoc 5 (entget (namedobjdict)))))) => T
 
I can't think of a scenario where I would want to add a non-graphical entity to a selection set.
回复

举报

66

主题

1552

帖子

1514

银币

后起之秀

Rank: 20Rank: 20Rank: 20Rank: 20

铜币
325
发表于 2022-7-5 17:26:05 | 显示全部楼层
 
Overthinking.
 
 
We don't know how the OP collects the handles - so thats just small additional check, not a big deal and will evaluate anyways (with or without checking).
回复

举报

26

主题

84

帖子

58

银币

初露锋芒

Rank: 3Rank: 3Rank: 3

铜币
130
发表于 2022-7-5 17:31:30 | 显示全部楼层
Thanks all for your kind help.
 
Problem resolved.
回复

举报

发表回复

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

本版积分规则

  • 微信公众平台

  • 扫描访问手机版

  • 点击图片下载手机App

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

GMT+8, 2025-3-15 03:16 , Processed in 0.566242 second(s), 68 queries .

© 2020-2025 乐筑天下

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