Jump to content

list box generated from text file


dan_g8

Recommended Posts

Hi,

 

can anyone point me in the right direction, i need to generate a user form that has a list box which is populated from a text file.

 

im normally a vba programmer which would be simples but am unsure the best way of doing this via lisp. can anyone point me in the right direction for the best way of doing this?

 

thanks

Link to comment
Share on other sites

In lisp you use dcl file instead of vba form.

Suppose you have a lsp file, a dcl file, a text file with ansi format, and a drawing dwg file. All locate in a same directory.

Your lsp file will be something like this.


(defun c:test ()
 (if (setq fname (findfile "test.txt"))
   (progn
     (setq file (open fname "r")
    l nil)
     (while (setq line (read-line file))
       (setq l (append l (list line)))
     )
     (close file)
     (setq i (load_dialog "listbox.dcl"))
     (if (not (new_dialog "Example" i)) (exit))
     (start_list "select")
     (mapcar 'add_list l)
     (end_list)
     (start_dialog) (unload_dialog i)
   )
 )
)

 

Your dcl file with the name "listbox.dcl" will be :

Example : dialog {label = "Test Dialog ";
  : list_box { label = "&Choose Section :";
               key = "select";
               multiple_select = true; }
    ok_cancel; 
  }

 

and your text file with the name "test.txt". In it you write things which appear in your listbox, lines separated with carry return.

Link to comment
Share on other sites

Here is another example of a DCl that asks for a single value rather than the the normal say getreal, its a generic lisp so you can use in any other lisp you have, either auto load or if from a menu (load "getval") (load "my lisp") The difference here is the DCL is within the lisp it writes a temporary DCL.

 

;; Input  Dialog box with variable title
;; By Ah June 2012 Thanks also to AlanJT for ideas
;; code (ah:getval title) returns sizze
;;(ah:getval "Please enter the size" 10 9 )
(defun AH:Getval (title width limit / fo)
(setq fname "C://acadtemp//getval.dcl")
(setq fo (open fname "w"))
(write-line "ddgetval : dialog {" fo)
(write-line " : row {" fo)
(write-line ": edit_box {" fo)
(write-line (strcat "    key = "  (chr 34) "sizze" (chr 34) ";") fo)
(write-line  (strcat " label = "  (chr 34) title (chr 34) ";"  )   fo)
; these can be replaced with shorter value etc
;(write-line "     edit_width = 18;" fo) 
;(write-line "     edit_limit = 15;" fo)
(write-line width fo) 
(write-line limit fo)
(write-line "   is_enabled = true;" fo)        
(write-line "    }" fo)
(write-line "  }" fo)
(write-line "ok_cancel;}" fo)
(close fo)
(setq dcl_id (load_dialog  "c:\\acadtemp\\getval"))
(if (not (new_dialog "ddgetval" dcl_id))
(exit))
(action_tile "sizze" "(setq item  $value)(done_dialog)")
(mode_tile "sizze" 3)
(start_dialog)
; returns the value of item
)

Link to comment
Share on other sites

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.
Note: Your post will require moderator approval before it will be visible.

Guest
Unfortunately, your content contains terms that we do not allow. Please edit your content to remove the highlighted words below.
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...