Jump to content
rcb007

Change color and plotstyles for Selected Xrefs

Recommended Posts

rcb007

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!

Share this post


Link to post
Share on other sites
BIGAL
Posted (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)
)

image.png.486e949ef5544e7ea1fd454307bd35f4.pngMulti radio buttons.lsp

Edited by BIGAL
  • Like 2

Share this post


Link to post
Share on other sites
rcb007

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)

 

Share this post


Link to post
Share on other sites
Lee Mac
Posted (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 by Lee Mac
  • Like 2

Share this post


Link to post
Share on other sites
rcb007

Lee! you make it look so simple with how you write your code. Thank you and it works awesomely! 

Share this post


Link to post
Share on other sites
Lee Mac
Posted (edited)

Thank you - I like to keep things simple 😉  I'm pleased the code is working well for you!

Edited by Lee Mac

Share this post


Link to post
Share on other sites
BIGAL

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)

 

Share this post


Link to post
Share on other sites
ronjonp
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.

Share this post


Link to post
Share on other sites
rcb007

Thanks BigAL, got it working. Its a interesting approach, I can see use with some other possible routines.

Share this post


Link to post
Share on other sites
BIGAL
Posted (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 by BIGAL

Share this post


Link to post
Share on other sites

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.

Guest
Reply to this topic...

×   Pasted as rich text.   Paste as plain text instead

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.


×
×
  • Create New...