Overlay xref and change color of xref layers

Overlay xref and change color of xref layers

Anonymous
Not applicable
1,844 Views
5 Replies
Message 1 of 6

Overlay xref and change color of xref layers

Anonymous
Not applicable

I have been using a lisp routine to xref overlay using standard settings for our office.

I now want to add a step to change the xref layer colors to 250 after the xref has been overlaid. 

I found portions of code in other forums to make this work but my problem is the portion of the code below just after the break using "nentsel"

I inserted the xref: (command "-xref" "o" filepath "0,0,0" "1" "1" "0"),

and know the name of the xref: (setq filename (vl-filename-base filepath))

but I do not know how to use the name to avoid using "nentsel"

Please take a look at this code below and let me know how to use the "filename" or any other idea you may have to have the color change automatically without having to select the xref mid-routine.

Thank you.

 

 (defun C:XR1 () (c:XREFLEVEL1))
(defun C:xreflevel1 ( / orglyr orgucs us)
(setq orglyr(getvar "clayer"))
(if(/=(getvar "WORLDUCS")1)
  (progn
   (command "ucs" "na" "d" "temp" "ucs" "na" "s" "temp")
   (setq orgucs(getvar "UCSFOLLOW"))
   (setvar "UCSFOLLOW" 0)
   (command "ucs" "w")
   (setq us T)))
 (setq filepath (getfiled "Select XREF File" "P:/Shared Folders/Projects/" "dwg" 8))
 (setq filename (vl-filename-base filepath))
 (command "-layer" "m" "------XR" "lo" "------XR" "")
 (command "-xref" "o" filepath "0,0,0" "1" "1" "0")




 (setq EN (nentsel "\nSelect Xref: ")) ;original
 (setq L (cdr (assoc 8 (entget (car EN))))) ;original
 (setq X (substr L 1 (vl-string-position (ascii "|") L)) )
 (setq AD (vla-get-ActiveDocument (vlax-get-Acad-Object)) layers (vla-get-Layers ad))
 (if  (/= (vl-string-search "|" L) nil)
  (progn
   (vlax-for layer layers
    (if (/= (vl-string-search (strcat  X "|") (vla-get-name layer)) nil)(vla-put-Color layer 250))
   )
   (command ".REGEN")
   )
   (alert "Not an Xref!")
 )
 

 

 

0 Likes
Accepted solutions (1)
1,845 Views
5 Replies
Replies (5)
Message 2 of 6

Ranjit_Singh
Advisor
Advisor
Accepted solution

maybe something like below. I used the code as is for attaching the xref and then changed the remaining portion for changing color

(defun c:xreflevel1  (/ a entdata filename filepath orglyr orgucs us)
 (setq orglyr (getvar "clayer"))
 (if (/= (getvar "WORLDUCS") 1)
  (progn (command "ucs" "na" "d" "temp" "ucs" "na" "s" "temp")
         (setq orgucs (getvar "UCSFOLLOW"))
         (setvar "UCSFOLLOW" 0)
         (command "ucs" "w")
         (setq us t)))
 (setq filepath (getfiled "Select XREF File" "P:/Shared Folders/Projects/" "dwg" 8))
 (setq filename (vl-filename-base filepath))
 (command "-layer" "m" "------XR" "lo" "------XR" "")
 (command "-xref" "o" filepath "0,0,0" "1" "1" "0")
 (while (setq a (tblnext "layer" (null a)))
  (and (wcmatch (cdr (assoc 2 a)) (strcat filename "|" "*"))
       (setq entdata (entget (tblobjname "layer" (cdr (assoc 2 a)))))
       (entmod (subst (cons 62 250) (assoc 62 entdata) entdata))))
 (princ))

 

Message 3 of 6

Anonymous
Not applicable

That is exactly what I was looking for!

Thank you very much for your help.

0 Likes
Message 4 of 6

Ranjit_Singh
Advisor
Advisor

Great. You are welcome.

0 Likes
Message 5 of 6

john.uhden
Mentor
Mentor

Um, why not just...

 

(command "_.-layer" "C" 250 "*|*" "")

?

 

That gets all the layers on all the xrefs.

John F. Uhden

0 Likes
Message 6 of 6

Anonymous
Not applicable

John,

We don't want all the layers on all the xrefs to be the same color. 

We're using this routine with different variances to allow some xrefs to be one color and others to be different colors. 

With the routine outlined in the solution, the routine we choose will auto change the color of the xref and not change the color of xref's already inserted.

Thank you for your suggestion though,

-Tim

0 Likes