乐筑天下

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

[编程交流] Simple fix (LISP noob) Syntax

[复制链接]

56

主题

256

帖子

230

银币

后起之秀

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

铜币
253
发表于 2022-7-5 19:42:44 | 显示全部楼层 |阅读模式
Hi all, I'm a casual basic lisper. Where in the code is wrong. I'm getting the ss with ssget. I want some error trapping to tell the users that nothing is selected. LISP selects all text regardless of layer. But this error I can't fix. I've tried looking at some examples but I can't get any to work.
 
This works when objects are selected:
  1. (defun c:SEL_TEXT_ALL ()(setq ss nil)   (setq ss (ssget '((0 . "MTEXT,TEXT"))))     (if (> (sslength ss) 0)       (progn               (command "Pselect" ss "")               (princ (strcat "\nNumber of found Text objects : < " (itoa (sslength ss)) " >"))               (setq ss nil)               (princ)       )       (princ (strcat "\n***  Nothing Selected  ***"))     ))
Error I get when nothing selected:
  1. Select objects:  ; error: bad argument type: lselsetp nil
EDIT: Is it good practice to clear the selection set before the progn is run?
回复

使用道具 举报

26

主题

1495

帖子

20

银币

初露锋芒

Rank: 3Rank: 3Rank: 3

铜币
118
发表于 2022-7-5 19:47:48 | 显示全部楼层
Maybe a simpler version :
 
  1. [b][color=BLACK]([/color][/b]defun c:stext [b][color=FUCHSIA]([/color][/b]/ ss[b][color=FUCHSIA])[/color][/b] [b][color=FUCHSIA]([/color][/b]if [b][color=NAVY]([/color][/b]setq ss [b][color=MAROON]([/color][/b]ssget '[b][color=GREEN]([/color][/b][b][color=BLUE]([/color][/b]0 . [color=#2f4f4f]"TEXT,MTEXT"[/color][b][color=BLUE])[/color][/b][b][color=GREEN])[/color][/b][b][color=MAROON])[/color][/b][b][color=NAVY])[/color][/b]     [b][color=NAVY]([/color][/b]princ [b][color=MAROON]([/color][/b]strcat [color=#2f4f4f]"\n"[/color] [b][color=GREEN]([/color][/b]itoa [b][color=BLUE]([/color][/b]sslength ss[b][color=BLUE])[/color][/b][b][color=GREEN])[/color][/b] [color=#2f4f4f]" Text Entities Found"[/color][b][color=MAROON])[/color][/b][b][color=NAVY])[/color][/b]     [b][color=NAVY]([/color][/b]princ [color=#2f4f4f]"\n*** Nothing Selected ***"[/color][b][color=NAVY])[/color][/b][b][color=FUCHSIA])[/color][/b] [b][color=FUCHSIA]([/color][/b]prin1[b][color=FUCHSIA])[/color][/b][b][color=BLACK])[/color][/b]
 
 
There is no real need to clear ss prior to the call.  (ssget) returns either nil or a PICKSET
 
I don't quite understand the PSelect command?  You have bound the variable ss to the PICKSET.  
 
I declared ss local to this function, but you could just as easily make it part of  larger 1.
 
-David
回复

使用道具 举报

63

主题

6297

帖子

6283

银币

后起之秀

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

铜币
358
发表于 2022-7-5 19:50:33 | 显示全部楼层
 
That is because you are trying to get the number of the selection set variable while it is equal to nil , so to get sure that the selection set variable has a selection just add the function add with the variable , eg.
 
 
  1.      (if (and ss (> (sslength ss) 0))
 
 
Actually the way you did write the routine is not the recommended one and you did take the longest way to reach the destination , so have a look about the following modification of your codes .
 
  1. (defun c:SEL_TEXT_ALL (/ ss) (if (setq ss (ssget '((0 . "MTEXT,TEXT"))))   (princ (strcat "\nNumber of found Text objects : < " (itoa (sslength ss)) " >" ))   (princ "\n***  Nothing Selected  ***") ) (sssetfirst nil ss) (princ))

 
Just ask if you have any doubts
回复

使用道具 举报

56

主题

256

帖子

230

银币

后起之秀

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

铜币
253
发表于 2022-7-5 19:54:12 | 显示全部楼层
Thanks guys for the quick responses. This forums great. Building up a LISP file with handy custom selection sets. Will post when I've completed it.
回复

使用道具 举报

56

主题

256

帖子

230

银币

后起之秀

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

铜币
253
发表于 2022-7-5 19:57:38 | 显示全部楼层
Trying to incorporate a fn found here:http://forums.autodesk.com/t5/visual-lisp-autolisp-and-general/how-to-filter-xrefs-out-from-ssget-list-cons-0-quot-insert-quot/m-p/2852572#M293570 for selection of blocks and not xrefs. Wrapping the if command like before doesn't work.
 
  1. (defun c:SEL_BLOCKS (/ ss);; FN by lpseifert @ http://forums.autodesk.com/t5/visual-lisp-autolisp-and-general/how-to-filter-xrefs-out-from-ssget-list-cons-0-quot-insert-quot/m-p/2852572#M293570           (if (setq ss (ssget (list (cons 0 "INSERT")))               idx -1)               (                   (repeat (sslength ss)                       (setq en (ssname ss (setq idx (1+ idx)))                           obj (vlax-ename->vla-object en)                           )                       (if                           (vlax-property-available-p obj 'Path)                           (progn                               (ssdel en ss)                               (setq idx (1- idx))                       )                       )                   )                   (princ (strcat "\nNumber of found Blocks : < " (itoa (sslength ss)) " >"))               )               (princ "\n***  Nothing Selected  ***")           )       (sssetfirst nil ss)   (princ))
回复

使用道具 举报

12

主题

395

帖子

384

银币

初露锋芒

Rank: 3Rank: 3Rank: 3

铜币
60
发表于 2022-7-5 20:01:06 | 显示全部楼层
Don't forget your progn!
  1. (defun c:SEL_BLOCKS (/ ss);; FN by lpseifert @ http://forums.autodesk.com/t5/visual-lisp-autolisp-and-general/how-to-filter-xrefs-out-from-ssget-list-cons-0-quot-insert-quot/m-p/2852572#M293570           (if (setq ss (ssget (list (cons 0 "INSERT")))               idx -1)               (progn                   (repeat (sslength ss)                       (setq en (ssname ss (setq idx (1+ idx)))                           obj (vlax-ename->vla-object en)                           )                       (if                           (vlax-property-available-p obj 'Path)                           (progn                               (ssdel en ss)                               (setq idx (1- idx))                       )                       )                   )                   (princ (strcat "\nNumber of found Blocks : < " (itoa (sslength ss)) " >"))               )               (princ "\n***  Nothing Selected  ***")           )       (sssetfirst nil ss)   (princ))
回复

使用道具 举报

12

主题

395

帖子

384

银币

初露锋芒

Rank: 3Rank: 3Rank: 3

铜币
60
发表于 2022-7-5 20:01:51 | 显示全部楼层
No, but seriously, that was all that was missing.
回复

使用道具 举报

56

主题

256

帖子

230

银币

后起之秀

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

铜币
253
发表于 2022-7-5 20:07:11 | 显示全部楼层
Thank you. When you're working and trying to learn LISP at the same time it's easy to miss out on the simplest thing.
 
EDIT, tried that but when nothings selected it's come with
  1. ; error: bad argument type: lselsetp nil
  1. (defun c:SEL_BLOCKS (/ ss);; FN by lpseifert @ http://forums.autodesk.com/t5/visual-lisp-autolisp-and-general/how-to-filter-xrefs-out-from-ssget-list-cons-0-quot-insert-quot/m-p/2852572#M293570           (if (setq ss (ssget (list (cons 0 "INSERT")))               idx -1)               [color=red][b]([/b][/color](progn                   (repeat (sslength ss)                       (setq en (ssname ss (setq idx (1+ idx)))                           obj (vlax-ename->vla-object en)                           )                       (if                           (vlax-property-available-p obj 'Path)                           (progn                               (ssdel en ss)                               (setq idx (1- idx))                       )                       )                   )               )               (princ (strcat "\nNumber of found Blocks : < " (itoa (sslength ss)) " >"))[color=red][b])[/b][/color]               (princ "\n***  Nothing Selected  ***")           )       (sssetfirst nil ss)   (princ))
Tried to wrap the progn up so that it was in the if and then (princ "\n***  Nothing Selected  ***") outside that for the else with extra parentheses but didn't work.
回复

使用道具 举报

114

主题

1万

帖子

1万

银币

中流砥柱

Rank: 25

铜币
543
发表于 2022-7-5 20:09:36 | 显示全部楼层
Hint: a setq expression will return the last value bound to the last symbol argument - in your case, the initial setq expression will return -1
回复

使用道具 举报

114

主题

1万

帖子

1万

银币

中流砥柱

Rank: 25

铜币
543
发表于 2022-7-5 20:11:56 | 显示全部楼层
Consider the following:
  1. (defun c:sel_blocks ( / def lst sel )   ;; Iterate over the block table and compile a list of xref blocks to exclude   (while (setq def (tblnext "block" (not def)))       (if (= 4 (logand 4 (cdr (assoc 70 def))))           (setq lst (vl-list* "," (cdr (assoc 2 def)) lst))       )   )   ;; Attempt to retrieve a selection of blocks (but not xrefs)   (if (setq sel (ssget (cons '(0 . "INSERT") (if lst (vl-list* '(-4 . "")))))))       (princ (strcat "\nNumber of blocks: " (itoa (sslength sel))))       (princ "\nNothing selected.")   )   (princ))
回复

使用道具 举报

发表回复

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

本版积分规则

  • 微信公众平台

  • 扫描访问手机版

  • 点击图片下载手机App

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

GMT+8, 2025-3-12 00:42 , Processed in 0.759937 second(s), 72 queries .

© 2020-2025 乐筑天下

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