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.
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 -
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
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
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.
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.
@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.
TharwaT313,
When I try that I get this error.
Command: TesT
; error: no function definition: VLAX-ENAME->VLA-OBJECT
Thanks
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) )
I am sorry for that , just add the following to the routine .
(vl-load-com)
Tharwat
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.
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.
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
Change the SSGET call so that it will only find XRefs that are NOT on the required layer.
Don Ireland
Engineering Design Technician
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?
@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.
// Called Kerry in my other life.
Everything will work just as you expect it to, unless your expectations are incorrect.
class keyThumper<T> : Lazy<T>; another Swamper
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) )
@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.
@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")
Can't find what you're looking for? Ask the community or share your knowledge.