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.


Registered forum members do not see this ad.
How to find out the list of existing blocks of the drawing and how to feed that list to the dialog box created by DCLplease help me. I need the lisp code.
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.
Lee Mac Programming
With Mathematics there is the possibility of perfect rigour, so why settle for less?
Just another Swamper




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
you need to create a list of block names here called LST then load above firstCode:(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 ) ) )
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) '<) )))
Last edited by BIGAL; 1st Oct 2012 at 01:37 am.
A man who never made mistakes never made anything
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.
Code:(setq pickedblock (car (AT:ListSelect "Title " "label" 10 10 "false" (vl-sort (vl-remove-if-not (function (lambda (x) (/= (vl-string-elt (car x) 0) 42)) ) list ) '< ) ) ) )
On this site I not only study AutoCAD but I also practice my English. If you find rough grammatical errors in my messages, please inform me with a personal message.


Thanks, Bigal's code is working.But the list is repeting the same block name several times.Can I stop it.




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.
A man who never made mistakes never made anything


Registered forum members do not see this ad.
Thanks again it works now nicely.
Bookmarks