Visual LISP, AutoLISP and General Customization
cancel
Showing results for 
Show  only  | Search instead for 
Did you mean: 

Moving xRefs to another layer

24 REPLIES 24
Reply
Message 1 of 25
TimDelbaereGCP
5431 Views, 24 Replies

Moving xRefs to another layer

Hi All,

 

I have been looking around the web to find a quick lsp routine that will take all the xrefs in a drawings and move them back onto layer "xref" or "0" depending on what the design team wants.

 

The ones I have found don't work or move all the xrefs to seperate layers.

 

Does anyone know of any that I can use or know where to look for them?

 

Thanks again for you help.

 

Tags (2)
24 REPLIES 24
Message 2 of 25

Hi,

 

>> take all the xrefs in a drawings and move them back onto layer "xref" or "0"

Command _QSELECT to select the xrefs and then assign them the layer you like, it's 5 clicks only!

 

- alfred -

------------------------------------------------------------------------------------
Alfred NESWADBA
Ingenieur Studio HOLLAUS ... www.hollaus.at ... blog.hollaus.at ... CDay 2024
------------------------------------------------------------------------------------
(not an Autodesk consultant)
Message 3 of 25

Sorry, I should have said they we have over 3000 files to go through and check and I wanted to be able to use Multi-Batch to automate it.

 

Thanks

Message 4 of 25
_Tharwat
in reply to: TimDelbaereGCP

This routine would change every Xref's to layer 0 .

 

(defun c:TesT (/ ss i vla)
  ;; Tharwat 31. Oct. 2011 ;;
  (if (setq ss (ssget "_x" '((0 . "INSERT"))))
    (repeat
      (setq i (sslength ss))
       (setq vla (vlax-ename->vla-object (ssname ss (setq i (1- i)))))
       (if (vlax-property-available-p vla 'Path)
         (vla-put-layer vla "0")
       )
    )
    (princ)
  )
  (princ)
)

 Tharwat

Message 5 of 25
dgorsman
in reply to: TimDelbaereGCP

Somewhat off-topic, but watch out for XREFs on layer 0.  Since XREFs are considered a block there can be some unforseen interactions with the DEFPOINTS layer setting, nested XREFs, and/or layer override settings.

----------------------------------
If you are going to fly by the seat of your pants, expect friction burns.
"I don't know" is the beginning of knowledge, not the end.


Message 6 of 25
scot-65
in reply to: TimDelbaereGCP

This is pieced together from a larger program I have... not tested.

 

   (while (setq d (tblnext "BLOCK" (not d)))
    (if (assoc 1 d)

     (command ".chprop" d "" "la" "0" "")
    );if

   );while

   (setq d nil)

 

What makes XRef's different than regular blocks is regular blocks do not have DFX 1.

You cannot do a ssget and use DFX 1 as a filter, it just will not work.

(I think it's because ssget was defined before XRef's were invented...?)

 

???


Scot-65
A gift of extraordinary Common Sense does not require an Acronym Suffix to be added to my given name.


Message 7 of 25
Kent1Cooper
in reply to: scot-65


@scot-65 wrote:

.... 

   (while (setq d (tblnext "BLOCK" (not d)))
    (if (assoc 1 d)

     (command ".chprop" d "" "la" "0" "")
....


I don't think that will work, because d is the data about a Block's or Xref's definition, but what they need to change the Layer of are all the insertions of that Xref, which you can't get at with (tblnext) -- what (tblnext) returns won't be accepted as object selection in a Chprop command.

Kent Cooper, AIA
Message 8 of 25
TimDelbaereGCP
in reply to: _Tharwat

TharwaT313,

 

When I try that I get this error.

 

Command: TesT
; error: no function definition: VLAX-ENAME->VLA-OBJECT

 

Thanks

Message 9 of 25
Lee_Mac
in reply to: TimDelbaereGCP

Here is another way, using tblnext:

 

(defun c:Xrefsto0 ( / a b c d e )

    (while (setq a (tblnext "BLOCK" (null a)))
        (if (= 4 (logand 4 (cdr (assoc 70 a))))
            (setq b (cons "," (cons (cdr (assoc 2 a)) b)))
        )
    )
    (if (and b (setq c (ssget "_X" (list '(0 . "INSERT") (cons 2 (apply 'strcat (cdr b)))))))
        (repeat (setq d (sslength c))
            (setq e (entget (ssname c (setq d (1- d)))))
            (entmod (subst (cons 8 "0") (assoc 8 e) e))
        )
    )
    (princ)
)

 

Message 10 of 25
_Tharwat
in reply to: TimDelbaereGCP

I am sorry for that , just add the following to the routine .

 

(vl-load-com)

 Tharwat

Message 11 of 25
scot-65
in reply to: Kent1Cooper

The original referenced program (created some 5 years and 2 months ago)

utilized command ".rename" "block" first (so the layer list is easier to read)

and then the following command is to change prop "Last" to layer 0.

I kinda knew it may not work here and disclaimed the code.

 

Lee_Mac's solution on how to grab the block looks like it will

work fine - I might have coded it a little differently by placing

ssget inside the while loop and eliminate the repeat...

 

???


Scot-65
A gift of extraordinary Common Sense does not require an Acronym Suffix to be added to my given name.


Message 12 of 25
scot-65
in reply to: TimDelbaereGCP

Here's a user friendly variation.

 

XRLC X-Ref Layer Change

 

Enjoy.

 


Scot-65
A gift of extraordinary Common Sense does not require an Acronym Suffix to be added to my given name.


Message 13 of 25
msarqui
in reply to: Lee_Mac

Hi Lee

 

I am using your routine for a while and it is really good.
For my purposes, I added a "create layer if not present" to put the xref in a specific layer.
Also, I put the routine on the Acaddoc.lsp to run everytime I open a drawing. I did this because not everyone in the office I work remembers to put the xref on the correct layer. That said, I would like to know if that is a way to have a "IF the xref is already on the Tx-Xref layer, do nothing". Did you catch my point?

 

(defun XrefstoXref ( / a b c d e )

;create layer if not present
 (if (tblsearch "layer" "Tx-Xref")
        (command "_.-layer" "_LO" "Tx-Xref" "_T" "Tx-Xref" "_ON" "Tx-Xref" "")
        (command "_.-layer" "_M" "Tx-Xref" "_LO" "Tx-Xref" "")
 );if

    (while (setq a (tblnext "BLOCK" (null a)))
        (if (= 4 (logand 4 (cdr (assoc 70 a))))
            (setq b (cons "," (cons (cdr (assoc 2 a)) b)))
        )
    )
    (if (and b (setq c (ssget "_X" (list '(0 . "INSERT") (cons 2 (apply 'strcat (cdr b)))))))
        (repeat (setq d (sslength c))
            (setq e (entget (ssname c (setq d (1- d)))))
            (entmod (subst (cons 8 "Tx-Xref") (assoc 8 e) e))
        )
    )
    (princ)
);defun
(XrefstoXref)

 

Thanks for any help.

Marcelo

Message 14 of 25
doni49
in reply to: msarqui

Change the SSGET call so that it will only find XRefs that are NOT on the required layer.



Don Ireland
Engineering Design Technician




If a reply solves your issue, please remember to click on "Accept as Solution". This will help other users looking to solve a similar issue. Thank you.


Please do not send a PM asking for assistance. That's what the forums are for. This allows everyone to benefit from the question asked and the answers given.

Message 15 of 25
msarqui
in reply to: doni49

Hi Don,

 

Thanks for the reply.
My knowledge in lisp is very basic, so I have no idea how to do this. Could you help me please?

 

 

Message 16 of 25
kdub_nz
in reply to: msarqui


@msarqui wrote:

Hi Don,

 

Thanks for the reply.
My knowledge in lisp is very basic, so I have no idea how to do this. Could you help me please?

 

 


Perhaps try something like this :

 


(setq ss-exceptXrefLayer (ssget "X" '((0 . "INSERT") (8 . "~XREF_*"))))

 Will select all Inserts except those on any layer thats name begins with "XREF_"

 

 

My habit aligns with  dgorsman's advice :  reduce the usage of layer "0" as much as possible.

 

//

Everything will work just as you expect it to, unless your expectations are incorrect.

class keyThumper<T> : Lazy<T>;      another  Swamper

Message 17 of 25
msarqui
in reply to: kdub_nz

Thanks Kerry, it works for me.
Message 18 of 25
andreas7ZYXQ
in reply to: msarqui

Im using Tharwats code and also trying do modify it to first search for an layer called x-ref and if it doesnt exists create it. After this move all xrefs there.

 

But im out in the dark now :s

 

;i want to implement this somehow
(command "_.layer" "_thaw" "YourLayerName" "_make" "YourLayerName" "_color' YourColor "" "")



(vl-load-com)
(defun c:xrefto0 (/ ss i vla)
  ;; Tharwat 31. Oct. 2011 ;;
  (if (setq ss (ssget "_x" '((0 . "INSERT"))))
    (repeat
      (setq i (sslength ss))
       (setq vla (vlax-ename->vla-object (ssname ss (setq i (1- i)))))
       (if (vlax-property-available-p vla 'Path)
         (vla-put-layer vla "0")
       )
    )
    (princ)
  )
  (princ)
)
Message 19 of 25
_Tharwat
in reply to: andreas7ZYXQ


@andreas7ZYXQ wrote:

Im using Tharwats code and also trying do modify it to first search for an layer called x-ref and if it doesnt exists create it. After this move all xrefs there.

 

But im out in the dark now :s

 

(or (tblsearch "LAYER" "x-ref")
(entmake (list '(0 . "LAYER")
'(100 . "AcDbSymbolTableRecord")
'(100 . "AcDbLayerTableRecord")
(cons 2 "x-ref")
'(70 . 0)
)
)
) (vl-load-com) (defun c:xrefto0 (/ ss i vla) ;; Tharwat 31. Oct. 2011 ;; (if (setq ss (ssget "_x" '((0 . "INSERT")))) (repeat (setq i (sslength ss)) (setq vla (vlax-ename->vla-object (ssname ss (setq i (1- i))))) (if (vlax-property-available-p vla 'Path) (vla-put-layer vla "0") ) ) (princ) ) (princ) )

Thank you for using my codes.

 

I have just added the codes that searches for the layer <x-ref> so if it is not found , just create it.

Message 20 of 25
Kent1Cooper
in reply to: andreas7ZYXQ


@andreas7ZYXQ wrote:

.... 

;i want to implement this somehow
(command "_.layer" "_thaw" "YourLayerName" "_make" "YourLayerName" "_color' YourColor "" "")

....
       (if (vlax-property-available-p vla 'Path)
         (vla-put-layer vla "0")
       )
....

You can do the Layer command you have there, substituting the appropriate Layer name and color, but with a double quote after the "_color" option.  Or, since you don't need that Layer to be made current [which the Make option will do, and which is why it needs to have the Layer thawed if it already exists, since it can't set a frozen Layer current], you can just do this:

(command "_.layer" "_new" "YourLayerName" "_color" YourColor "YourLayerName" "")

 

If it already exists, it won't matter.  If it already exists with the wrong color, that will be corrected.  If it already exists and is frozen or off, presumably there's some reason for that, and Xrefs will still be moved to it anyway.

 

And, I presume you want that last line quoted above to be:


  (vla-put-layer vla "YourLayerName")

 

Kent Cooper, AIA

Can't find what you're looking for? Ask the community or share your knowledge.

Post to forums  

Autodesk Design & Make Report

”Boost