HI I am trying to change existing drawing properties values in AUTOCAD with pop list below and just cant get there. Is there anyone who could help edit the code.
lisp
Code:
(defun c:building ( / *error* UpdateList data dclfile dclhandle )
;; Accompanying DCL File:
(setq dclFile "building.dcl")
(defun *error* ( msg )
;; Error Handler - will unload the dialog
;; from memory should the user decide to hit Esc
(if dclHandle (unload_dialog dclHandle))
(or (wcmatch (strcase msg) "*BREAK,*CANCEL*,*EXIT*")
(princ (strcat "\n** Error: " msg " **")))
(princ)
)
(defun UpdateList ( key lst )
;; This function updates the list_box associated with the specified key
;; using the contents of the supplied lst
(start_list key)
(mapcar 'add_list lst)
(end_list)
)
;; Data used to Populate List_Boxes:
;; I've chosen to use this list structure because it suits the data,
;; but there are many other possibilities.
(setq Data
'(
("Tillson Nbr. 1 - 383 " (" 120 Tillson, Amherst, MA"))
("Tillson Nbr. 2 - 384 " (" 121 Tillson, Amherst, MA"))
("Tillson Nbr. 3 - 385 " (" 122 Tillson, Amherst, MA"))
("Tillson Nbr. 4 - 157 " (" 123 Tillson, Amherst, MA"))
("Tillson Nbr. 5 - 158 " (" 124 Tillson, Amherst, MA"))
("Tillson Nbr. 6 - 160 " (" 135 Tillson, Amherst, MA"))
)
)
;; Start of Main Routine
;; Lots of Error Trapping to make sure the Dialog Loads:
(cond
( (<= (setq dclHandle (load_dialog dclFile)) 0)
(princ "\n--> DCL File not Found.")
)
( (not (new_dialog "building" dclHandle))
(setq dclHandle (unload_dialog dclHandle))
(princ "\n--> Dialog Definition not Found.")
)
( t
;; Dialog Loaded Successfully.
(or *Name* (setq *Name* "0"))
(or *Address* (setq *Address* "0"))
;; Set up some default selections, for the first-time running of the program.
;; The variables *Name* & *Address* are intended to be global and hence will
;; remember the user's last selections.
;; Populate the List_Boxes:
;; List_Box 'lst1'
(UpdateList "lst1" (mapcar 'car Data))
(set_tile "lst1" *Name*)
;; List_Box 'lst2'
(UpdateList "lst2" (cadr (nth (atoi *Name*) Data)))
(set_tile "lst2" *Address*)
;; Action_tile Statements:
;; These control what happens when the user interacts with a tile in the dialog.
(action_tile "lst1"
(strcat
"(UpdateList \"lst2\" (setq lst2 (cadr (nth (atoi (setq *Name* $value)) Data))))"
"(setq *Address*"
" (set_tile \"lst2\""
" (if (< (atoi *Address*) (length lst2)) *Address* \"0\")"
" )"
")"
)
)
;; Here, when the user selects an item from 'lst1', the UpdateList subfunction
;; is fired to update the items in list_box 'lst2'.
;; list_box 'lst2' is also set to the value of *Address* if the index is
;; available for the selected item, else the first item is selected.
;; Note that $value is a string containg the index of the item
;; that the user has selected.
(action_tile "lst2" "(setq *Address* $value)")
;; Dialog setup, lets start it:
(start_dialog)
(setq dclHandle (unload_dialog dclHandle))
)
)
(princ)
)
dcl
// DCL File to be saved as building.dcl
lbox : popup_list { width = 50; fixed_width = true; alignment = centered; }
building : dialog { label ="Building"; spacer;
: row {
: lbox { key = "lst1"; label = "Name" ; }
: lbox { key = "lst2"; label = "Address"; }
}
ok_only;
}