(defun c:OrdLinDim
( / *error* UpdateList data dclfile dclhandle
)
;; This program demonstrates how to update a secondary list_box based
;; on user selection from a primary list_box.
;; Example courtesy of Lee Mac © 2010 (www.lee-mac.com)
;; Accompanying DCL File:
(setq dclFile
"OrdLinDim_ColDia.dcl")
;; Ensure this file resides in an AutoCAD Support Path
;; Error Handler - will unload the dialog
;; from memory should the user decide to hit Esc
)
(defun UpdateList
( key lst
)
;; This function updates the list_box associated with the specified key
;; using the contents of the supplied lst
)
;; 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.
'(
("DimLinear" ("BLDG_" "BLDG_001" "BLDG_015" "BLDG_150" "PANEL_BOX" "PANEL_BOX_001" "PANEL_BOX_015" "PANEL_BOX_150"))
("DimOrdinate" ("MODD" "PANEL_BOX" "PANEL_BOX_001" "PANEL_BOX_015" "PANEL_BOX_150"))
)
)
;; Start of Main Routine
;; Lots of Error Trapping to make sure the Dialog Loads:
(princ "\n--> DCL File not Found.") )
(princ "\n--> Dialog Definition not Found.") )
( t
;; Dialog Loaded Successfully.
(or *Dstyle
* (setq *DStyle
* "0")) (or *DType
* (setq *DType
* "0"))
;; Set up some default selections, for the first-time running of the program.
;; The variables *Insert* & *Annonation* are intended to be global and hence will
;; remember the user's last selections.
;; Populate the List_Boxes:
;; List_Box 'lst1'
;; List_Box 'lst2'
;; Action_tile Statements:
;; These control what happens when the user interacts with a tile in the dialog.
"(UpdateList \"lst2\" (setq lst2 (cadr (nth (atoi (setq *DStyle* $value)) Data))))"
"(setq *DStyle*"
"(set_tile \"lst2\""
" (if (< (atoi *DStyle*) (length lst2)) *DStyle* \"0\")" ;;
")"
")"
)
)
;;(setvar "Clayer" "DIMEN")
;;(setq dim1 (getvar 'dimscale))
;;(command "cecolor" "bylayer")
;;(setq dim (getvar 'dimscale))
;;(command "-dimstyle" "R" Dstyle)
;;(command "dimscale" dim1)
;;(command "DIMORDINATE")
;;(while (< 0 (getvar 'cmdactive)) ;; While the command is active, pause
;; (command "\\") ;; Pause for user input
;; ) ;; end WHILE |;
;; 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 *DStyle* if the index is
;; available for the selected item, else the first item is selected.
;; Note that $value is a string containing the index of the item
;; that the user has selected.
;; Dialog setup, lets start it:
)
)
)