PDA

View Full Version : return layer name from dialog box



Mark Thomas
7th May 2004, 06:12 pm
Present the user with a small dialog box listing the layers in the current dwg. the selected layer name is returned as a string. The .dcl file is created on the fly then deleted.


;;; creates a temporary .dcl file
(defun mktemp-dcl (/ tmpf tmpfo)
(vl-load-com)
(setq tmpf (vl-filename-mktemp nil nil ".dcl")
tmpfo (open tmpf "w")
)
(write-line
(strcat
"layer_d : dialog {
label = \"Current Layers\" ;
: popup_list {
label = \"Choose a Layer:\";
key = \"sel\";
value = \"0\" ;
edit_width = 30;
}
ok_cancel ;
}"
)
tmpfo
)
(close tmpfo)
tmpf
)

;;; returns the Layers object
(defun get-layrobj ()
(vla-get-Layers
(vla-get-ActiveDocument
(vlax-get-acad-object)
)
)
)

;;; generates a list of layer names in the current dwg.
(defun layer-lst (/ lst)
(vlax-for l (get-layrobj)
(setq lst
(cons (vlax-get-property l 'Name) lst)
)
)
(if lst (acad_strlsort lst))
)

;;; present the user with a dialog box
(defun layer-lister (/ db dcl_id lst user_event layr)
(setq db (mktemp-dcl)
dcl_id (load_dialog db)
lst (layer-lst)
)
(if (not (new_dialog "layer_d" dcl_id))
(exit)
)

(start_list "sel")
(mapcar 'add_list lst)
(end_list)

(action_tile "accept"
(strcat
"(progn (setq layr (atof (get_tile \"sel\")))
(done_dialog) (setq user_event T))"
)
)
(action_tile "cancel"
"(done_dialog)"
)

(start_dialog)
(unload_dialog dcl_id)

(if user_event
(progn
(setq layr (fix layr)) ;convert to integer
(setq layr (nth layr lst)) ;get the layer
(vl-file-delete db)
)
)
layr
)