乐筑天下

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

[编程交流] List of Blocks & feed to dialo

[复制链接]

171

主题

447

帖子

276

银币

中流砥柱

Rank: 25

铜币
860
发表于 2022-7-6 07:27:58 | 显示全部楼层 |阅读模式
How to find out the list of existing blocks of the drawing  and how to feed that list to the dialog box created by DCL:? please help me. I need the lisp code.
回复

使用道具 举报

114

主题

1万

帖子

1万

银币

中流砥柱

Rank: 25

铜币
543
发表于 2022-7-6 07:40:19 | 显示全部楼层
Use the tblnext function to iterate over the Block Table, or vlax-for if you wish to use Visual LISP to iterate over the Blocks Collection.
 
There are many examples to be found on the forum.
回复

使用道具 举报

106

主题

1万

帖子

101

银币

顶梁支柱

Rank: 50Rank: 50

铜币
1299
发表于 2022-7-6 07:54:13 | 显示全部楼层
Search here for a lisp by AlanJT that creates the dialouge code and then like Lee Above would display answer will see if I can find.
 
here is code by AlanJT
 
  1. (defun AT:ListSelect (title label height width multi lst / fn fo d item f) ;; List Select Dialog (Temp DCL list box selection, based on provided list) ;; title - list box title ;; label - label for list box ;; height - height of box ;; width - width of box ;; multi - selection method ["true": multiple, "false": single] ;; lst - list of strings to place in list box ;; Alan J. Thompson, 09.23.08 / 05.17.10 (rewrite) (setq fo (open (setq fn (vl-filename-mktemp "" "" ".dcl")) "w")) (foreach x (list (strcat "list_select : dialog { label = "" title ""; spacer;")                  (strcat ": list_box { label = "" label "";" "key = "lst";")                  (strcat "allow_accept = true; height = " (vl-princ-to-string height) ";")                  (strcat "width = " (vl-princ-to-string width) ";")                  (strcat "multiple_select = " multi "; } spacer; ok_cancel; }")            )   (write-line x fo) ) (close fo) (new_dialog "list_select" (setq d (load_dialog fn))) (start_list "lst") (mapcar (function add_list) lst) (end_list) (setq item (set_tile "lst" "0")) (action_tile "lst" "(setq item $value)") (setq f (start_dialog)) (unload_dialog d) (vl-file-delete fn) (if (= f 1)   ((lambda (s / i s l)      (while (setq i (vl-string-search " " s))        (setq l (cons (nth (atoi (substr s 1 i)) lst) l))        (setq s (substr s (+ 2 i)))      )      (reverse (cons (nth (atoi s) lst) l))    )     item   ) ))
 
you need to create a list of block names here called LST then load above first
 

[code]do block list here lst heres a start not tested (vl-load-com)  (setq adoc (vla-get-activedocument (vlax-get-acad-object)))  (vla-startundomark adoc)  (vlax-for i (vla-get-blocks adoc)  (setq lst (cons (cons (vla-get-name i) i) lst))); here is calling section(setq pickedblock (car (AT:ListSelect   "Title "   "label"   10   10   "false"   (vl-sort (mapcar (function car) lst) '
回复

使用道具 举报

2

主题

74

帖子

72

银币

初来乍到

Rank: 1

铜币
10
发表于 2022-7-6 08:02:42 | 显示全部楼层
 
Such a function will create a list of the same and false (phantom) blocks with an asterisk (*) at the beginning of the name, I suspect the author of such unnecessary.
 
  1. (setq pickedblock      (car (AT:ListSelect      "Title "      "label"      10      10      "false"      (vl-sort        [b](vl-remove-if-not          (function            (lambda (x) (/= (vl-string-elt (car x) 0) 42))          )          list        )[/b]        '<      )    )      ))
回复

使用道具 举报

171

主题

447

帖子

276

银币

中流砥柱

Rank: 25

铜币
860
发表于 2022-7-6 08:17:22 | 显示全部楼层
Thanks, Bigal's code is working.But the list is repeting the same block name several times.Can I stop it.
回复

使用道具 举报

106

主题

1万

帖子

101

银币

顶梁支柱

Rank: 50Rank: 50

铜币
1299
发表于 2022-7-6 08:23:01 | 显示全部楼层
Are you running it more than once if so LST will grow you need to set lst back to nil each time or do at start.
回复

使用道具 举报

171

主题

447

帖子

276

银币

中流砥柱

Rank: 25

铜币
860
发表于 2022-7-6 08:33:29 | 显示全部楼层
Thanks  again it works now nicely.
回复

使用道具 举报

发表回复

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

本版积分规则

  • 微信公众平台

  • 扫描访问手机版

  • 点击图片下载手机App

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

GMT+8, 2025-3-10 04:49 , Processed in 0.694800 second(s), 66 queries .

© 2020-2025 乐筑天下

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