; Hdmi6 function radio buttons & popup list to insert block & update attributes ; sample dwg: Cable Test.dwg ; OP: ; https://forums.autodesk.com/t5/visual-lisp-autolisp-and-general/insert-block-with-attributes-using-dcl/m-p/13116708#M473951 (defun c:Hdmi6 (/ *error* att-desc att-manu att-model attreq blk-name dcl dcl-id dcl-name do_clr_dcl do_manu_select do_pop_lst_box do_radio_button do_wrt_dcl hdmi-model hdmi-manu L2 num setup_dcl stid layerName ) ; localize functions and variables ;;;---load vl functions (if(not(car (atoms-family 1 '("vl-load-com"))))(vl-load-com)) ;;; ; define error function (defun *error* (msg) (and msg (not (wcmatch (strcase msg) "*CANCEL*,*QUIT*,*BREAK*,*EXIT*")) (princ (strcat "\nError: " msg)) ) ;;;---terminate any dialog display (term_dialog) (if attreq (setvar "attreq" attreq)) ; restore original settiing (if (or dcl-id dcl) ;;;---Unload & clear the dialog box (do_clr_dcl dcl-id dcl) ) (princ) ) ; defun ;;; ;;;--- begin sub functions ;;; ;;; do_clr_dcl function unloads & deletes dcl (defun do_clr_dcl (id df) ;;;---Unload the dialog box (if id (unload_dialog id)) ;;;--- delete dialog box file (if df (vl-file-delete df)) ) ; defun do_clr_dcl ;;; do_wrt_dcl function writes dcl file on the fly ; Argument: ; name = dcl filename (defun do_wrt_dcl (name / dlg-len fp name-only usr-nam) (if (and name (setq fp (open name "w") name-only (vl-filename-base name)) ) (mapcar '(lambda (x)(write-line x fp)) (list "dcl_settings : default_dcl_settings { audit_level = 3; }" "" (strcat " " name-only " : dialog { " ) " label = \"HDMI CONNECTORS\"; " " : row { " " : column { " " : boxed_radio_column { " " label = \"Choose Manufacturer\"; " " : radio_button { " " key = \"LIBERTY\"; " " label = \"LIBERTY\"; " " } " " : radio_button { " " key = \"EXTRON\"; " " label = \"EXTRON\"; " " } " " : radio_button { " " key = \"C2G\"; " " label = \"C2G\"; " " } " " } " " } " " } " " : row { " " : boxed_column { " " : popup_list {" " label = \"Choose Connector Length\"; " " key = \"L2\";" " edit_width = 8;" " }" " : spacer {" " height = 0;" " }" " } " " } " " : row { " " ok_cancel; " " } " "} " ) ; list ) ; mapcar ) ; if (if fp (close fp)) ) ; defun do_wrt_dcl ;;; setup_dcl sets up for dcl (defun setup_dcl (name) ;---write dcl on the fly passing on name (do_wrt_dcl (setq dcl (strcat (getenv "Temp") "\\" name ".dcl"))) ;---Load the dcl file from disk into memory (if (not (setq dcl-id (load_dialog dcl))) ;;;---Then, fail to load dcl (progn (alert (strcat name ".dcl File Could Not Be Loaded!")) (exit) ) ) ; if ) ; defun setup_dcl ;;; do_manu_select (defun do_manu_select (itm) (cond ((eq itm "LIBERTY") (setq L2 '("3FT" "6FT" "10FT" "15FT" "20FT" "24FT")) ) ((eq itm "EXTRON") (setq L2 '("3FT" "6FT" "9FT" "12FT" "15FT")) ) ((eq itm "C2G") (setq L2 '("3FT" "6FT" "10FT" "12FT" "15FT")) ) ) ) ;;; do_pop_lst_box populates list box (defun do_pop_lst_box (lst / pos) ;;;--- populate list box (start_list "L2" 3) (mapcar 'add_list lst) (end_list) (if(not *hdmi-model*)(setq *hdmi-model* (nth 0 lst))) ; setup 1st item as default (if hdmi-model ; chk if this value is set (setq pos (vl-position hdmi-model lst)) ; then chk if item is on the list (setq pos (vl-position *hdmi-model* lst)) ; else chk if default item is on the list ) (if pos (set_tile "L2" (itoa pos)) ; then select item (progn (setq hdmi-model (nth 0 lst)) ; else select 1st item on list (set_tile "L2" "0") ) ) ) ; defun do_pop_lst_box ;;; do_radio_button (defun do_radio_button () (if (not *hdmi-manu*)(setq *hdmi-manu* "LIBERTY")) (set_tile *hdmi-manu* "1") ; select default ) ;;; ;;; begin main program ;;; ;; Ensure the layer exists, if not, create it (setq layerName "_AVSF-LN VIDEO") (if (not (tblsearch "layer" layerName)) ;; then create it (command "._LAYER" "_M" layerName "_C" "160" "" "") (progn ; else ;; make sure layer is thawed, turned on & unlocked (command "_.LAYER" "_T" layerName "_On" layerName "_UnL" layerName "") ;; Set the current layer to the desired layer (setvar "CLAYER" layerName) ) ) ;;;---Define some variables that will be used later (if (not *dlg-pos*)(setq *dlg-pos* '(-1 -1))) ;;;---Setup list items for list box & dcl name (setq dcl-name "Hdmi" blk-name "_AVSF-PRT CBL-LBL" ; block name att-manu "MANU" ; attribute name att-model "MODEL" ; attribute name att-desc "DESC" ; attribute description ) ;;;---Sets up for dcl (setup_dcl dcl-name) ;;;---Load the dialog definition inside the DCL file (if (not (new_dialog dcl-name dcl-id "" *dlg-pos*)) ;;;---Then, the dialog name was not found in dcl (progn (alert (strcat "The " dcl-name " Window Could Not Be Found!")) ;;;---Unload & clear the dialog box (do_clr_dcl dcl-id dcl) (exit) ) ;;;---Else, the dialog name was found in dcl (progn ;;;---Setup defaults (do_radio_button) ; select radio button (do_pop_lst_box (do_manu_select *hdmi-manu*)) ; populate list box based on manufacturer ;;;---Setup actions ;;;---For click radio buttons (foreach tile '("LIBERTY" "EXTRON" "C2G") (action_tile tile "(do_pop_lst_box (do_manu_select (setq hdmi-manu $key)))") ) ;;;---For click list box action (action_tile "L2" "(setq hdmi-model (nth (atoi $value) L2))") ;;;---For selecting ok button (action_tile "accept" "(setq *dlg-pos* (done_dialog 1))") ; close dialog & save position ;;;---For selecting cancel button (action_tile "cancel" "(done_dialog 0)") ; close dialog ;;;---Display the dialog box and await for return values (setq stid (start_dialog)) (if(zerop stid) (alert (strcat dcl-name " is Cancelled")) (progn ; else (if hdmi-manu (setq *hdmi-manu* hdmi-manu)) (if hdmi-model (setq *hdmi-model* hdmi-model)) ; save defaults (setq attreq (getvar "attreq")) ; save current settings (setvar "attreq" 0) ; disable attribute dialog appearance ; insert block at scale of 1 and rotation of 0 (command "_.Insert" blk-name "_S" "1" "_R" "0") (while (= 1 (logand 1 (getvar 'CMDACTIVE))) (command pause)) ; pick insertion point (setpropertyvalue (entlast) att-manu *hdmi-manu*) ; fill in manufacturer (setpropertyvalue (entlast) att-desc (strcat *hdmi-model* " HDMI M TO M")) ; fill in description (setq num (atoi *hdmi-model*)) ; convert length to number (cond ((eq *hdmi-manu* "LIBERTY") (if (< num 10) ; chk if single digit (setq num "HDPMM0") ; then add 0 to model (setq num "HDPMM") ; else just use model ) (setpropertyvalue (entlast) att-model (strcat num (substr *hdmi-model* 1 (1- (strlen *hdmi-model*))))) ; drop last letter ) ((eq *hdmi-manu* "EXTRON") (if (< num 10) ; chk if single digit (setq num (strcat "0" (itoa num))) ; then add 0 in front and convert to string (setq num (itoa num)) ; else just convert to string ) (setpropertyvalue (entlast) att-model (strcat "26-663-" num)) ) ((eq *hdmi-manu* "C2G") (cond ((eq *hdmi-model* "3FT") (setpropertyvalue (entlast) att-model "56782") ) ((eq *hdmi-model* "6FT") (setpropertyvalue (entlast) att-model "56783") ) ((eq *hdmi-model* "10FT") (setpropertyvalue (entlast) att-model "56784") ) ((eq *hdmi-model* "12FT") (setpropertyvalue (entlast) att-model "50611") ) ((eq *hdmi-model* "15FT") (setpropertyvalue (entlast) att-model "50612") ) ) ) ) ; cond (setvar "attreq" attreq) ; restore settings ;; Ensure the layer exists, if not, create it (setq layerName "DEFPOINTS") (if (not (tblsearch "layer" layerName)) ;; then create it (command "._LAYER" "_M" layerName "_C" "141" "" "") (progn ; else ;; make sure layer is thawed, turned on & unlocked (command "_.LAYER" "_T" layerName "_On" layerName "_UnL" layerName "") ;; Set the current layer to the desired layer (setvar "CLAYER" layerName) ) ) (princ "\nCurrent layer reset to DEFPOINTS.") ) ; progn ) ; if ) ; progn ) ; if ;;;---Unload & clear the dialog box (do_clr_dcl dcl-id dcl) (princ) ; clean exit ) ; defun (princ "\n...Type Hdmi6 to Start Command.")(princ)