rcb007 Posted April 5, 2021 Posted April 5, 2021 I need some help adding a dialog box selection to this routine. Right now it works when I select an xref. But i would like to apply this to several xrefs but not all. I thought a dialog might work but any other ideas? (defun C:SelectXrefstoFormat (/ xrsel xrdata xrname) (if (and (setq xrsel (entsel "\nSelect Xrefs to format...")) ;;<<< Possible for a dialog box users can select? (setq xrdata (entget (car xrsel))) (member '(0 . "INSERT") xrdata) (= (logand 4 (cdr (assoc 70 (tblsearch "block" (setq xrname (cdr (assoc 2 xrdata))))))) 4) ) (command "_.layer" "_color" 252 (strcat xrname "|*") "_pstyle" 252 (strcat xrname "Shade 50%") "_color" 150 (strcat xrname "|C-PVMT-ASPH," xrname "|C-PVMT-CONC," xrname "|C-PVMT-GRVL") "_freeze" (strcat xrname "|X-TOPO-TEXT") "") ) ) Thank you! Quote
BIGAL Posted April 5, 2021 Posted April 5, 2021 (edited) Try this you need to save the Multi Radio buttons.lsp to a support path for it to work can be used in any program will work with up to about 20 xref names. If you have more then 20 need to use a listbox library routine see Lee-mac.com. (defun choosexref ( / lst doc blocks n but) (vl-load-com) (setq lst '()) (setq doc (vla-get-ActiveDocument (vlax-get-acad-object))) (setq blocks (vla-get-Blocks doc)) (vlax-for n blocks (if (eq (vla-get-IsXref n) :vlax-true) (progn (setq xname (vl-string-translate (chr 92) (strcat (chr 92)(chr 92)) (vla-get-path n))) (setq lst (cons xname lst)) ) ) ) (setq lst (cons "Please choose xref" lst)) (if (not AH:Butts)(load "Multi Radio buttons.lsp")) (if (= but nil)(setq but 1)) (setq xrsel (ah:butts but "V" lst)) (princ) ) Multi radio buttons.lsp Edited April 5, 2021 by BIGAL 2 Quote
rcb007 Posted April 6, 2021 Author Posted April 6, 2021 Awesome! Just a crazy question. How do I tie this together with the original routine? You do bring up a good point about lots of XRefs. I think the list box might be a good idea. I have the list box function. Just having a hard time, like the above, having it it work with my routine. lol ;; List Box - Lee Mac ;; Displays a DCL list box allowing the user to make a selection from the supplied data. ;; msg - [str] Dialog label ;; lst - [lst] List of strings to display ;; bit - [int] 1=allow multiple; 2=return indexes ;; Returns: [lst] List of selected items/indexes, else nil (defun LM:listbox ( msg lst bit / dch des tmp rtn ) (cond ( (not (and (setq tmp (vl-filename-mktemp nil nil ".dcl")) (setq des (open tmp "w")) (write-line (strcat "listbox:dialog{label=\"" msg "\";spacer;:list_box{key=\"list\";multiple_select=" (if (= 1 (logand 1 bit)) "true" "false") ";width=50;height=15;}spacer;ok_cancel;}" ) des ) (not (close des)) (< 0 (setq dch (load_dialog tmp))) (new_dialog "listbox" dch) ) ) (prompt "\nError Loading List Box Dialog.") ) ( t (start_list "list") (foreach itm lst (add_list itm)) (end_list) (setq rtn (set_tile "list" "0")) (action_tile "list" "(setq rtn $value)") (setq rtn (if (= 1 (start_dialog)) (if (= 2 (logand 2 bit)) (read (strcat "(" rtn ")")) (mapcar '(lambda ( x ) (nth x lst)) (read (strcat "(" rtn ")"))) ) ) ) ) ) (if (< 0 dch) (unload_dialog dch) ) (if (and tmp (setq tmp (findfile tmp))) (vl-file-delete tmp) ) rtn ) ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;; (defun choosexref ( / lst doc blocks n but) (vl-load-com) (setq lst '()) (setq doc (vla-get-ActiveDocument (vlax-get-acad-object))) (setq blocks (vla-get-Blocks doc)) (vlax-for n blocks (if (eq (vla-get-IsXref n) :vlax-true) (progn (setq xname (vl-string-translate (chr 92) (strcat (chr 92)(chr 92)) (vla-get-path n))) (setq lst (cons xname lst)) ) ) ) (setq lst (cons "Please choose xref" lst)) (if (not AH:Butts)(load "Multi Radio buttons.lsp")) (if (= but nil)(setq but 1)) (setq xrsel (ah:butts but "V" lst)) (princ) ) ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;; (defun C:SelectXrefstoFormat (/ xrsel xrdata xrname) (if (and (setq xrsel (entsel "\nSelect Xrefs to format...")) ;;<<< Possible for a dialog box users can select? (setq xrdata (entget (car xrsel))) (member '(0 . "INSERT") xrdata) (= (logand 4 (cdr (assoc 70 (tblsearch "block" (setq xrname (cdr (assoc 2 xrdata))))))) 4) ) (command "_.layer" "_color" 252 (strcat xrname "|*") "_pstyle" "Shade 50%" (strcat xrname "|*") "_color" 150 (strcat xrname "|C-PVMT-ASPH," xrname "|C-PVMT-CONC," xrname "|C-PVMT-GRVL") "_freeze" (strcat xrname "|X-TOPO-TEXT") "") ) ) (C:SelectXrefstoFormat) Quote
Lee Mac Posted April 6, 2021 Posted April 6, 2021 (edited) Here's a quick (untested) adaption of your code to integrate a call to my LM:listbox function: (defun c:formatxr ( / cmd def lst ) (while (setq def (tblnext "block" (not def))) (if (= 4 (logand 4 (cdr (assoc 70 def)))) (setq lst (cons (cdr (assoc 2 def)) lst)) ) ) (if lst (progn (setq cmd (getvar 'cmdecho)) (setvar 'cmdecho 0) (foreach xrf (LM:listbox "Select Xrefs to Format" (acad_strlsort lst) 1) (command "_.-layer" "_color" 252 (strcat xrf "|*") "_pstyle" "Shade 50%" (strcat xrf "|*") "_color" 150 (strcat xrf "|C-PVMT-ASPH," xrf "|C-PVMT-CONC," xrf "|C-PVMT-GRVL") "_freeze" (strcat xrf "|X-TOPO-TEXT") "" ) ) (setvar 'cmdecho cmd) ) (princ "\nNo xrefs are defined in the active drawing.") ) (princ) ) Edited April 6, 2021 by Lee Mac 2 Quote
rcb007 Posted April 6, 2021 Author Posted April 6, 2021 Lee! you make it look so simple with how you write your code. Thank you and it works awesomely! Quote
Lee Mac Posted April 6, 2021 Posted April 6, 2021 (edited) Thank you - I like to keep things simple I'm pleased the code is working well for you! Edited April 6, 2021 by Lee Mac Quote
BIGAL Posted April 6, 2021 Posted April 6, 2021 Lee provided a excellent answer as usual. Regarding how to use multi radio buttons. You will need to modify the (if as the (and may not work now also. A simple test may be when making the list of xrefs does it exist if not dont proceed. (setq xrsel (entsel "\nSelect Xrefs to format...")) ;;<<< Possible for a dialog box users can select? (choosexref) Quote
ronjonp Posted April 7, 2021 Posted April 7, 2021 4 hours ago, BIGAL said: Lee provided a excellent answer as usual. Regarding how to use multi radio buttons. You will need to modify the (if as the (and may not work now also. A simple test may be when making the list of xrefs does it exist if not dont proceed. (setq xrsel (entsel "\nSelect Xrefs to format...")) ;;<<< Possible for a dialog box users can select? (choosexref) @BIGAL Sometime more is not always better. IMO, succinct and thorough answers will always rule. Quote
rcb007 Posted April 7, 2021 Author Posted April 7, 2021 Thanks BigAL, got it working. Its a interesting approach, I can see use with some other possible routines. Quote
BIGAL Posted April 8, 2021 Posted April 8, 2021 (edited) Glad to hear. There are Multi getvals, Mutil toggles, Getval with image and will add Radio buttons multi columns soon. Cadtutor\downloads, RLX also has some excellent DCL library style routines worth searching for. Edited April 8, 2021 by BIGAL Quote
Recommended Posts
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.