Refer to selected Xref in Macro using "-xref"

Refer to selected Xref in Macro using "-xref"

tim312324
Participant Participant
375 Views
4 Replies
Message 1 of 5

Refer to selected Xref in Macro using "-xref"

tim312324
Participant
Participant

Hello,

 

I am trying to customize the right-click menu for when an Xref is selected.  Unfortunately, I cannot figure out how to refer to the selected Xref within the Macro.  When I run each of the following commands from the right-click menu, the command executes for all Xrefs.  Is it possible to edit the commands so the selected Xref is the only one that is unloaded, reloaded, detached, etc?

 

Unload: -xref u *

Reload: -xref r *

Detach: -xref d *

Bind: -xref b *

 

Any help is much appreciated.  I apologize if this has been answered clearly before.  I am not a programmer and just want to restore a functionality I got used to CAD having in college.  

 

 

 

0 Likes
Accepted solutions (1)
376 Views
4 Replies
Replies (4)
Message 2 of 5

pendean
Community Legend
Community Legend
While you wait... your macros inclusion of * is asking the command you want ALL: literally, it is what you are asking it to do. Now you know.

If you are NOT an LT user, explore this oldie LISP (change the UNLOAD option to whatever you need) https://cadtips.cadalyst.com/dwg/unload-xref
Message 3 of 5

ВeekeeCZ
Consultant
Consultant
Accepted solution

Unfortunately, it can't be that simple.

Unless you're on LT, you can use the following LISP.

 

Use one of THESE methods to make the lisp loaded, then for menu macro use just the bolded command name. 

 

(vl-load-com)
(defun c:XrefSelectedUnload nil (SelectXrefTo "Unload") (princ)) (defun c:XrefSelectedReload nil (SelectXrefTo "Reload") (princ)) (defun c:XrefSelectedDetach nil (SelectXrefTo "Detach") (princ)) (defun SelectXrefTo (method / doc blocks :proceed s i o) ; ---------- Unload/Reload/Detach (defun :proceed (o) (and o (or (vlax-property-available-p o 'Path) (prompt "\nSelected object was not XREF.")) (setq n (vlax-get o 'Name)) (not ((eval (read (strcat "vla-" method))) (vla-item blocks n))) (princ (strcat "\nXref " method "ed: " n)))) (setq doc (vla-get-ActiveDocument (vlax-get-acad-object)) blocks (vla-get-Blocks doc)) (if (and (setq s (ssget "_I" '((0 . "INSERT")))) (not (vla-startundomark doc))) (repeat (setq i (sslength s)) (:proceed (vlax-ename->vla-object (ssname s (setq i (1- i)))))) (while (setq o (car (entsel (strcat "\nSelect xref to " method ": ")))) (:proceed (vlax-ename->vla-object o)))) (vla-endundomark doc) (princ) )

 

Message 4 of 5

paullimapa
Mentor
Mentor

Perhaps in college you were using AutoCAD and not LT?  LT doesn’t support lisp code whereas AutoCAD does. 


Paul Li
IT Specialist
@The Office
Apps & Publications | Video Demos
0 Likes
Message 5 of 5

tim312324
Participant
Participant

Thanks so much, I have been looking for this solution for a while!  

 

For anyone using this lisp to create a command: delete the default ^C^C that the cui puts at the beginning of the macro.  

 

image_2023-01-23_095307125.png

 

a beautiful sight tot see!