Jump to content

XRefsToLayers.LSP [Move XRefs to corresponding layers]


Recommended Posts

Posted (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.

x2lb.PNG

 

When completed, prints number of XRef moved to each layer.

x2la.PNG

 

Example of created layers:

x2lc.PNG

 

Comments and criticism are always welcome.

Enjoy guys. :)

XRefsToLayers.LSP

Edited by alanjt
Posted

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)
)

@+

Posted
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.

Posted

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.

 

@+

Posted
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.

 

@+

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.

Posted

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 :D

 

The main thing is that the lisp works as desired and especially that one is happy with his work

 

@+

Posted
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 :D

Ah, but experimentation is the spice of life.:wink:

  • 3 weeks later...
Posted

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.

Posted
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.

Posted
Thanks Alanjt.

Cheers, PP.

Enjoy. :)...

  • 5 years later...
Posted

Hi Alan,

Wondered if this lisp could be updated to also do pdfs?

Thanks

Pad

  • 1 year later...
Posted

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

Posted
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. :)

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
Unfortunately, your content contains terms that we do not allow. Please edit your content to remove the highlighted words below.
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  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...