alanjt Posted April 27, 2010 Posted April 27, 2010 (edited) Inspired by this thread. Will move all XRefs to layers, based on name and prefix of "0-XREF_" (can be changed to whatever). Prompts user with option to lock XRef layers. When completed, prints number of XRef moved to each layer. Example of created layers: Comments and criticism are always welcome. Enjoy guys. XRefsToLayers.LSP Edited May 17, 2011 by alanjt Quote
Patrick_35 Posted April 27, 2010 Posted April 27, 2010 Hi An example (defun c:x2l(/ *AcadDoc* s x old new lst nom) (vl-load-com) (setq *AcadDoc* (vla-get-activedocument (vlax-get-acad-object)) s "" ) (vla-startundomark *AcadDoc*) (vlax-for x (vla-get-blocks *AcadDoc*) (and (eq (vla-get-isxref x) :vlax-true) (setq s (strcat s (vla-get-name x) ",")) ) ) (or (= s "") (not (ssget "x" (list (cons 0 "insert") (cons 2 s)))) (initget 0 "Yes No") (eq (getkword "\nXRefs To Layers\nLock XRef layers? [Yes/No] <Yes>: ") "No") (progn (vlax-for x (setq ss (vla-get-activeselectionset *AcadDoc*)) (vla-put-lock (vla-item (vla-get-layers *AcadDoc*) (setq nom (vla-get-layer x))) :vlax-true) (if (setq old (assoc nom lst)) (setq new (cons (car old) (1+ (cdr old))) lst (subst new old lst) ) (setq lst (cons (cons nom 1) lst)) ) ) (vla-delete ss) (alert (apply 'strcat (mapcar '(lambda (x) (strcat "\n" (itoa (cdr x)) " XRef(s) on layer: \"" (car x) "\"" ) ) (vl-sort lst '(lambda(a b)(< (car a) (car b)))) ) ) ) ) ) (vla-endundomark *AcadDoc*) (princ) ) @+ Quote
alanjt Posted April 27, 2010 Author Posted April 27, 2010 Hi An example Thanks. A slimmed down version. BTW, you are defining the layer database for each object you step through and you leave layers you unlock unlocked. Not a big deal, just thought I'd make you aware. Quote
Patrick_35 Posted April 27, 2010 Posted April 27, 2010 I made it simple, because with multiple checks, you lose efficiency and speed If the layer is already locked, not serious as it is the result we want I also used a list to the list of layers and xrefs, easier to handle and faster. I just kept the strcat the variable s because of ssget, otherwise it would have been as a list I also used subtle or as a condition of multiple Also look at how structured the lisp and the logic You have a good level and very little to learn lisp. Simplifies just a little what you do because you have an error handler that is not justified. @+ Quote
alanjt Posted April 27, 2010 Author Posted April 27, 2010 I made it simple, because with multiple checks, you lose efficiency and speedIf the layer is already locked, not serious as it is the result we want I also used a list to the list of layers and xrefs, easier to handle and faster. I just kept the strcat the variable s because of ssget, otherwise it would have been as a list I also used subtle or as a condition of multiple Also look at how structured the lisp and the logic You have a good level and very little to learn lisp. Simplifies just a little what you do because you have an error handler that is not justified. @+ I appreciate your comments, but I would say my only redundancy is my list check at the end. I could remove it before issuing the lock to all XRef layers and the alert, but it's minimal and is a nanosecond of a setback at best. I like your use of or for your conditional. You do realize that what you have modified the code to do is to only lock/unlock the layers XRefs reside on. Mine actually creates and puts them on layers pertaining to the XRef name. And I would say that my *error* handler is justified. eg. Command: x2l XRefs To Layers Lock XRef layers? [Yes/No] <Yes>: *Cancel* Command: Command: u Start of Group encountered. Must enter UNDO END to go back further. However you could avoid this if you moved your undomark between the progn and your step through the active selectionset, but I prefer to wrap it in an error handler to avoid this all together. Quote
Patrick_35 Posted April 27, 2010 Posted April 27, 2010 To each his preferences It is always interesting to see the other lisp to understand and find tips Personally, I still prefer the speed to the beauty of a code, but one does not preclude the other The main thing is that the lisp works as desired and especially that one is happy with his work @+ Quote
alanjt Posted April 27, 2010 Author Posted April 27, 2010 To each his preferences It's nice that you gave everyone an option to only freeze/thaw XRef layers. It is always interesting to see the other lisp to understand and find tips Agreed. Personally, I still prefer the speed to the beauty of a code, but one does not preclude the other Ah, but experimentation is the spice of life.:wink: Quote
Phiphi Posted May 19, 2010 Posted May 19, 2010 I wish to have a lisp routine to keep selected layers of any Xrefs in a drawing. All the rest of layers will be turn off or freeze after a right click. I used to Xref Civil drawings into my working file but need few layers of road to show only. It takes so much time to turn off hundreds of layers in many Xrefs. Can you please help. Tkx. PP. Quote
alanjt Posted May 19, 2010 Author Posted May 19, 2010 I wish to have a lisp routine to keep selected layers of any Xrefs in a drawing. All the rest of layers will be turn off or freeze after a right click. I used to Xref Civil drawings into my working file but need few layers of road to show only. It takes so much time to turn off hundreds of layers in many Xrefs. Can you please help. Tkx. PP. I'd be more than happy to help you with something like this. What do you have so far in code? You should start a new thread for a question like this. Quote
Least Posted July 29, 2015 Posted July 29, 2015 Hi Alan, Wondered if this lisp could be updated to also do pdfs? Thanks Pad Quote
tzframpton Posted January 5, 2017 Posted January 5, 2017 I didn't realize there was already a request in back in July. I was coming here to request images, and/or all items that the XREF manager controls. Would love for this to include the extra items. -TZ Quote
alanjt Posted January 5, 2017 Author Posted January 5, 2017 I didn't realize there was already a request in back in July. I was coming here to request images, and/or all items that the XREF manager controls. Would love for this to include the extra items. -TZ Never noticed the June request...from 2015. I'll get something up by the end of the week. 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.