+ Reply to Thread
Results 1 to 7 of 7
  1. #1
    Senior Member
    Discipline
    Construction
    wimal's Discipline Details
    Occupation
    cadoperator
    Discipline
    Construction
    Using
    AutoCAD 2006
    Join Date
    Oct 2011
    Location
    sri lanka
    Posts
    142

    Default List of Blocks & feed to dialog box

    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 DCL please help me. I need the lisp code.

  2. #2
    Quantum Mechanic Lee Mac's Avatar
    Computer Details
    Lee Mac's Computer Details
    Operating System:
    Windows 7 Ultimate (32-bit)
    Discipline
    Multi-disciplinary
    Lee Mac's Discipline Details
    Discipline
    Multi-disciplinary
    Details
    Custom Programming / Software Customisation
    Using
    AutoCAD 2013
    Join Date
    Aug 2008
    Location
    London, England
    Posts
    15,816

    Default

    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

  3. #3
    Forum Deity
    Using
    Civil 3D 2013
    Join Date
    Dec 2005
    Location
    GEELONG AUSTRALIA
    Posts
    3,798

    Default

    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

    Code:
    (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) '<)
      )))
    Last edited by BIGAL; 1st Oct 2012 at 01:37 am.
    A man who never made mistakes never made anything

  4. #4
    Senior Member Geobuilder's Avatar
    Computer Details
    Geobuilder's Computer Details
    Operating System:
    Windows 7 Professional
    CPU:
    Intel(R) Corel(TM) i7 860 @ 2.80GHz 2.80 GHz
    RAM:
    8 GB DDR2
    Graphics:
    NVIDIA GeForce GTS 250 (Microsoft Corporation - WDDM v1.1)
    Monitor:
    22 "
    Using
    AutoCAD 2013
    Join Date
    Jan 2010
    Location
    Russia, Siberia
    Posts
    206

    Default

    Quote Originally Posted by BIGAL View Post
    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) '<)
      )))
    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.

  5. #5
    Senior Member
    Discipline
    Construction
    wimal's Discipline Details
    Occupation
    cadoperator
    Discipline
    Construction
    Using
    AutoCAD 2006
    Join Date
    Oct 2011
    Location
    sri lanka
    Posts
    142

    Default

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

  6. #6
    Forum Deity
    Using
    Civil 3D 2013
    Join Date
    Dec 2005
    Location
    GEELONG AUSTRALIA
    Posts
    3,798

    Default

    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

  7. #7
    Senior Member
    Discipline
    Construction
    wimal's Discipline Details
    Occupation
    cadoperator
    Discipline
    Construction
    Using
    AutoCAD 2006
    Join Date
    Oct 2011
    Location
    sri lanka
    Posts
    142

    Default

    Registered forum members do not see this ad.

    Thanks again it works now nicely.

Similar Threads

  1. Building a List of Coordinates to Feed to the Trim Command
    By Bill Tillman in forum AutoLISP, Visual LISP & DCL
    Replies: 0
    Last Post: 8th Feb 2012, 05:01 pm
  2. How to update list in dialog boxes?
    By sharpooth in forum AutoLISP, Visual LISP & DCL
    Replies: 8
    Last Post: 1st Dec 2010, 12:07 pm
  3. List of blocks??
    By AQucsaiJr in forum AutoCAD General
    Replies: 5
    Last Post: 13th Aug 2010, 03:27 pm
  4. Variable for inserting blocks without dialog box
    By EvilSi in forum AutoCAD General
    Replies: 2
    Last Post: 17th Sep 2008, 09:50 am
  5. List of arguments for 'render' dialog box
    By sylvan in forum AutoLISP, Visual LISP & DCL
    Replies: 1
    Last Post: 30th Dec 2005, 12:16 am

Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts