乐筑天下

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

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

[复制链接]

12

主题

395

帖子

384

银币

初露锋芒

Rank: 3Rank: 3Rank: 3

铜币
60
发表于 2022-7-5 20:15:40 | 显示全部楼层
Way to keep it simple, Lee.
 
To reiterate what Lee's initial point was You need set your 'idx' variable else where, like this.
  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(setq idx -1)           (if (setq ss (ssget (list (cons 0 "INSERT"))))                              ((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))
回复

使用道具 举报

56

主题

256

帖子

230

银币

后起之秀

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

铜币
253
发表于 2022-7-5 20:17:55 | 显示全部楼层
Thanks this creates a selection set. after it's run it selects nothing. Is it suppose to?
 
 
Thanks, this now creates an error when blocks have been selected. The opposite of what was happening.
  1. Number of found Blocks : < 3 >; error: no function definition: nil
回复

使用道具 举报

26

主题

1495

帖子

20

银币

初露锋芒

Rank: 3Rank: 3Rank: 3

铜币
118
发表于 2022-7-5 20:22:50 | 显示全部楼层
 
Looks good Lee.
 
Is there no longer a limit to the string length of a filter ?
 
-David
回复

使用道具 举报

56

主题

256

帖子

230

银币

后起之秀

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

铜币
253
发表于 2022-7-5 20:25:45 | 显示全部楼层
Please forgive my blatant disregard for learning anything. Lunch break has helped me figure it out.
Working code to select blocks only. Thanks Lee Mac.
 
  1. (defun c:sel_blocks ( / def lst sel ); FN by Lee Mac http://www.cadtutor.net/forum/showthread.php?92638-Simple-fix-%28LISP-noob%29-Syntax-problem&p=633824&viewfull=1#post633824   ;; 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 "\n***  Nothing Selected  ***")   )   (sssetfirst nil sel)   (princ))
How can I expand on this to select only annotative blocks. Where can I find good info for this?
 
EDIT: I have a code for the selection of non associative hatches:
  1. (setq ss (ssget '((0 . "HATCH") (-4 . "=") (71 . 0))))
What fn has (-4 . "=") (71 . 0)
 
Do they relate to the standard filter dialog in any way?
回复

使用道具 举报

114

主题

1万

帖子

1万

银币

中流砥柱

Rank: 25

铜币
543
发表于 2022-7-5 20:27:11 | 显示全部楼层
 

 
 
No problem - as you've gathered, the sssetfirst function will highlight & grip a given selection set, though, even without this function and without highlighting & gripping the selection set, Select > Previous will still acquire the selection set obtained by ssget.
 
 
Thanks David
 
 
A character limit for DXF string groups in the selection filter list may still exist, though, I am not sure exactly what that limit may be as I have not encountered issues up to now.
 
Of course, an alternative approach to circumvent any potential character limit could be simply:
  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 (cons (assoc 2 def) lst))       )   )   ;; Attempt to retrieve a selection of blocks (but not xrefs)   (if (setq sel (ssget (cons '(0 . "INSERT") (if lst (append '((-4 . "")))))))       (princ (strcat "\nNumber of blocks: " (itoa (sslength sel))))       (princ "\nNothing selected.")   )   (princ))
 
Annotative data complicates matters somewhat - consider the following:
  1. (defun c:sel_blocks ( / ano def sel xrf )   (while (setq def (tblnext "block" (not def)))       (setq blk (assoc 2 def))       (cond           (   (= 4 (logand 4 (cdr (assoc 70 def))))               (setq xrf (cons blk xrf))           )           (   (= 1                   (cdr                       (assoc 1070                           (reverse                               (cadr                                   (assoc -3                                       (entget                                           (cdr                                               (assoc 330                                                   (entget                                                       (tblobjname "block" (cdr blk))                                                   )                                               )                                           )                                       )                                   )                               )                           )                       )                   )               )               (setq ano (cons blk ano))           )       )   )   (if       (setq sel           (ssget               (append '((0 . "INSERT"))                   (if ano                       (append                          '((-4 . ""))                       )                   )                   (if xrf                       (append                          '((-4 . ""))                       )                   )               )           )       )       (princ (strcat "\nNumber of blocks: " (itoa (sslength sel))))       (princ "\nNothing selected.")   )   (sssetfirst nil sel)   (princ))
 
You may find my ssget function reference helpful in this regard - though, in your example, the '(-4 . "=") is not actually required as the ssget filter list uses an implicit AND logic (that is, by default every item in the list must match).
回复

使用道具 举报

26

主题

1495

帖子

20

银币

初露锋芒

Rank: 3Rank: 3Rank: 3

铜币
118
发表于 2022-7-5 20:33:11 | 显示全部楼层
 
 
I still see references of 'approximately 500 character limit' for wcmatch and that ssget follows it's rules.  
 
-David
回复

使用道具 举报

56

主题

256

帖子

230

银币

后起之秀

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

铜币
253
发表于 2022-7-5 20:34:02 | 显示全部楼层
Thanks, I've attached an example I've tested on. Saved in 2010 ACAD. The code you posted selects non-Anno blocks in this example.
 
Test Drawing Annotative Verus Non Anno Blocks.dwg
 
So, maybe would the process be easier say if I just wanted to select all annotative objects instead using something like:
  1. (setq ss1 (ssget "all" ))
and then apply a filter after this to select Anno objects. ACAD Help does not list these filters completely or am I missing something?
 
This will complete my quest for quick selection tools.
回复

使用道具 举报

114

主题

1万

帖子

1万

银币

中流砥柱

Rank: 25

铜币
543
发表于 2022-7-5 20:38:13 | 显示全部楼层
 
After a quick test, I'm not seeing that limit with wcmatch:
  1. _$ (setq str "x")"x"_$ (repeat 500 (setq str (strcat "x" str)))"xxxxxxxxxxx...xxxxxxxxxxxxx"_$ (strlen str)501_$ (wcmatch str "*x*")T_$ (repeat 500 (setq str (strcat "a" str)))"aaaaaaaaaaaaaaa...xxxxxxxxxxx"_$ (strlen str)1001_$ (wcmatch str "*x*")T_$ (repeat 500 (setq str (strcat "b" str)))"bbbbbbbbbbbb...xxxxxxxxxxxxxxx"_$ (strlen str)1501_$ (wcmatch str "*x*")T
回复

使用道具 举报

26

主题

1495

帖子

20

银币

初露锋芒

Rank: 3Rank: 3Rank: 3

铜币
118
发表于 2022-7-5 20:41:30 | 显示全部楼层
From 2000 -> 2004 help and 2012 Autodesk exchange
 
 
Go figure    -David
回复

使用道具 举报

114

主题

1万

帖子

1万

银币

中流砥柱

Rank: 25

铜币
543
发表于 2022-7-5 20:44:42 | 显示全部楼层
 
Sorry, I had overlooked a few things:
  1. (defun c:sel_blocks ( / blk def lst sel )   (while (setq def (tblnext "block" (not def)))       (setq blk (cdr (assoc 2 def)))       (cond           (   (= 4 (logand 4 (cdr (assoc 70 def))))               (setq lst (cons (cons 2 (LM:escapewildcards blk)) lst))           )           (   (/= 1                   (cdr                       (assoc 1070                           (reverse                               (cadr                                   (assoc -3                                       (entget                                           (cdr                                               (assoc 330                                                   (entget                                                       (tblobjname "block" blk)                                                   )                                               )                                           )                                          '("AcadAnnotative")                                       )                                   )                               )                           )                       )                   )               )               (setq lst (cons (cons 2 (LM:escapewildcards blk)) lst))           )       )   )   (if lst       (if (setq sel (ssget (append '((0 . "INSERT") (-4 . "")))))           (princ (strcat "\nNumber of blocks: " (itoa (sslength sel))))           (princ "\nNothing selected.")       )       (princ "\nNo valid blocks found in drawing.")   )   (sssetfirst nil sel)   (princ));; Escape Wildcards  -  Lee Mac;; Escapes wildcard special characters in a supplied string(defun LM:escapewildcards ( str )   (vl-list->string       (apply 'append           (mapcar              '(lambda ( c )                   (if (member c '(35 64 46 42 63 126 91 93 45 44))                       (list 96 c)                       (list c)                   )               )               (vl-string->list str)           )       )   ))
Escape Wildcards function from here.
 
Note that the above code will still not be compatible with annotative dynamic blocks, as these will require yet more checks.
 
 
Correct - the developer documentation in AutoCAD is not complete.
回复

使用道具 举报

发表回复

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

本版积分规则

  • 微信公众平台

  • 扫描访问手机版

  • 点击图片下载手机App

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

GMT+8, 2025-3-12 00:45 , Processed in 0.632002 second(s), 77 queries .

© 2020-2025 乐筑天下

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