Jump to content

Recommended Posts

Posted

Okay so here is my problem, i have a client drawing that has 22 xrefs and i need to change the color of each xref (all layers included in xref) into a different color. so I have been manually going into the layer manager and then highlighting all the layers on the xref and changing its color to a set colour and so on till i end up with, xref 1 all layers = red, xref 2 all layers = blue etc..

 

is it possible to create a lisp to do this for me, i have looked through the forums and found several lisps that can change the layers of a selected xref but not in the same method i.e. by name

 

any help would be great?

 

regards

Glen

  • Replies 29
  • Created
  • Last Reply

Top Posters In This Topic

  • GlnGrnr

    10

  • Tharwat

    7

  • alanjt

    4

  • pBe

    4

Top Posters In This Topic

Posted

Try something like this .

 

(vl-load-com)
(defun ChangeXrefLayerColor (color XrefName / doc)
 (vlax-for x (vla-get-layers (setq doc (vla-get-activedocument (vlax-get-acad-object))))
   (if (wcmatch (strcase (vla-get-name x)) (strcat XrefName "|*"))
     (vla-put-color x color)
   )
 )
 (vla-regen doc acAllViewports)
 (princ)
)

Posted
Try something like this .

 

(vl-load-com)
(defun ChangeXrefLayerColor (color XrefName)
 (vlax-for x (vla-get-layers (vla-get-activedocument (vlax-get-acad-object)))
   (if (wcmatch (strcase (vla-get-name x)) (strcat XrefName "|*"))
     (vla-put-color x color)
   )
 )
 (princ)
)

 

 

how do i get this to run, i caved it as a.lsp and apploaded it but when i type the command (ChangeXrefLayerColor) it does not run

 

thanks for such a quick response Tharwat

Posted

Example of usage ...

 

*- Number 2 indicates to color number 1 = red

*- "BASEMENT represents the Xref name and it supposed to be in Capital letters .

 

(ChangeXrefLayerColor 1 "BASEMENT")

 

NOTE : I updated the codes , so consider the new modified one to test .

Posted

I must be missing something as I am getting a syntax error. here is the code i have changed slightly

 

(vl-load-com)

(defun ChangeXrefLayerColor (1 "0618_AC" / doc)

(vlax-for x (vla-get-layers (setq doc (vla-get-activedocument (vlax-get-acad-object))))

(if (wcmatch (strcase (vla-get-name x)) (strcat XrefName "|*"))

(vla-put-color x color)

)

)

(vla-regen doc acAllViewports)

(princ)

)

Posted

Just load the codes that I posted in my first post then copy and paste this in the command line .

 

(ChangeXrefLayerColor 1 "0618_AC")

Posted (edited)

This could be quickly accomplished from the commandline version of LAYER (aka -Layer or -LA).

eg.

Command: LA
-LAYER
Current layer:  "0"
Enter an option 
[?/Make/Set/New/Rename/ON/OFF/Color/Ltype/LWeight/TRansparency/MATerial/Plot/Fre
eze/Thaw/LOck/Unlock/stAte/Description/rEconcile]: C

New color [Truecolor/COlorbook] : 6

Enter name list of layer(s) for color 6 (magenta) <0>: *|*

No matching layer names found.
Enter an option 
[?/Make/Set/New/Rename/ON/OFF/Color/Ltype/LWeight/TRansparency/MATerial/Plot/Fre
eze/Thaw/LOck/Unlock/stAte/Description/rEconcile]:

 

Take note that "*|*" as your layer name filter will selected only xref layers.

 

Now, I do have this routine that I use from time-to-time...

 

(defun c:XCC (/ xrefs lst color name)
 ;; XRef Color Change (change color of objects in selected XRef(s)
 ;; Required subroutines: AT:ListSelect
 ;; Alan J. Thompson, 02.09.11 / 2013.10.10
 (vlax-for x (vla-get-blocks
               (cond (*AcadDoc*)
                     ((setq *AcadDoc* (vla-get-activedocument (vlax-get-acad-object))))
               )
             )
   (if (eq (vla-get-isXRef x) :vlax-true)
     (setq xrefs (cons (strcase (strcat (vla-get-name x) "|*")) xrefs))
   )
 )

 (cond ((not (setq xrefs (vl-sort xrefs '<))) (alert "No XRefs in drawing"))
       ((and (setq lst (AT:ListSelect "Select XRef(s) to change: " "" 10 10 "true" xrefs))
             (setq color (acad_colordlg 1 nil))
        )
        (vlax-for x (vla-get-layers *AcadDoc*)
          (setq name (strcase (vla-get-name x)))
          (if (vl-some (function (lambda (xref) (wcmatch name xref))) lst)
            (vla-put-color x color)
          )
        )

        (vla-regen *AcadDoc* acAllViewports)

       )
 )
 (princ)
)

(vl-load-com)

(defun AT:ListSelect (title label height width multi lst / fn fo d item f)
 ;; List Select Dialog (Temp DCL list box selection, based on provided list)
 ;; title - list box title
 ;; label - label for list box
 ;; height - height of box
 ;; width - width of box
 ;; multi - selection method ["true": multiple, "false": single]
 ;; lst - list of strings to place in list box
 ;; Alan J. Thompson, 09.23.08 / 05.17.10 (rewrite)
 (setq fo (open (setq fn (vl-filename-mktemp "" "" ".dcl")) "w"))
 (foreach x (list (strcat "list_select : dialog { label = \"" title "\"; spacer;")
                  (strcat ": list_box { label = \"" label "\";" "key = \"lst\";")
                  (strcat "allow_accept = true; height = " (vl-princ-to-string height) ";")
                  (strcat "width = " (vl-princ-to-string width) ";")
                  (strcat "multiple_select = " multi "; } spacer; ok_cancel; }")
            )
   (write-line x fo)
 )
 (close fo)
 (new_dialog "list_select" (setq d (load_dialog fn)))
 (start_list "lst")
 (mapcar (function add_list) lst)
 (end_list)
 (setq item (set_tile "lst" "0"))
 (action_tile "lst" "(setq item $value)")
 (setq f (start_dialog))
 (unload_dialog d)
 (vl-file-delete fn)
 (if (= f 1)
   ((lambda (s / i s l)
      (while (setq i (vl-string-search " " s))
        (setq l (cons (nth (atoi (substr s 1 i)) lst) l))
        (setq s (substr s (+ 2 i)))
      )
      (reverse (cons (nth (atoi s) lst) l))
    )
     item
   )
 )
)

Edited by alanjt
Posted

Nice work Alan , a line of codes to regen afterall would be perfect ;)

Posted

too slow :lol:

 

(defun c:xcolorsequence	(/ a col xrs)
 (setq	col 0
xrs nil
 )
 (while (setq a (tblnext "block" (not a)))
   (if	(assoc 1 a)
     (setq xrs (cons (cdr (assoc 2 a)) xrs))
   )
 )

 (foreach itm (acad_strlsort xrs)
   (command "_layer"
     "_color"
     (setq col (1+ col))
     (strcat itm "|*")
     ""
   )
 )
 (princ)
)

Posted
Nice work Alan , a line of codes to regen afterall would be perfect ;)

Done and done.

Posted
too slow :lol:

 

A few minutes late better than not coming .

Welcome back pBe :)

Posted
A few minutes late better than not coming .

 

Indeed

 

Welcome back pBe :)

 

Thank you tharwat, Its nice to be back :)

Posted

Hi Alanjt, thanks for your help but that script does not seem to work on mine. also i woudl have to select each xref in turn to change the color, what i would like to do is run one script to change all xrefs to certain colors in one go.

 

Tharwat, that works beautifully, now my question wil be how can i get this to run as a single line executable ( i.e. defun C:rainbow xrefs (etc..) against all xrefs. so for example if i run this code below it changes it all in one run, which is great but how can i change the drawing name (0618) to change depending on the drawing i have open i tired to use the wildcard (*_AC) for example but that did not work

 

(vl-load-com)

(defun ChangeXrefLayerColor (color XrefName / doc)

(vlax-for x (vla-get-layers (setq doc (vla-get-activedocument (vlax-get-acad-object))))

(if (wcmatch (strcase (vla-get-name x)) (strcat XrefName "|*"))

(vla-put-color x color)

)

)

(vla-regen doc acAllViewports)

(princ)

)

(ChangeXrefLayerColor 1 "0618__AC")

(ChangeXrefLayerColor 2 "0618__BM")

(ChangeXrefLayerColor 3 "0618__CL")

(ChangeXrefLayerColor 4 "0618__EC")

(ChangeXrefLayerColor 5 "0618__FE")

(ChangeXrefLayerColor 6 "0618__FL")

(ChangeXrefLayerColor 7 "0618__FP")

(ChangeXrefLayerColor 11 "0618__GC")

(ChangeXrefLayerColor 41 "0618__HD")

(ChangeXrefLayerColor 71 "0618__HO")

(ChangeXrefLayerColor 91 "0618__HW")

(ChangeXrefLayerColor 121 "0618__MW")

(ChangeXrefLayerColor 151 "0618__PA")

(ChangeXrefLayerColor 171 "0618__RE")

(ChangeXrefLayerColor 191 "0618__RP")

(ChangeXrefLayerColor 211 "0618__SL")

(ChangeXrefLayerColor 241 "0618__TL")

(ChangeXrefLayerColor 222 "0618__ZA")

(ChangeXrefLayerColor 144 "0618__ZB")

(ChangeXrefLayerColor 30 "0618__ZC")

Posted

Well now, if you have a specific xref-names and corresponding color, we can utilize that list to change the colors in one go. Play around with the code i posted using your list, pretty sure you'll get it.

Posted

Untested:

 

(defun _xrefLayerColorChange (xrefNameColorList)
 ((lambda (lst / name color)
    (vlax-for layer (vla-get-layers (vla-get-activedocument (vlax-get-acad-object)))
      (if (setq name  (strcase (vla-get-name layer))
                color (vl-some (function (lambda (x)
                                           (if (wcmatch name (car x))
                                             (cdr x)
                                           )
                                         )
                               )
                               lst
                      )
          )
        (vla-put-color layer color)
      )
    )
  )
   (mapcar (function (lambda (x) (cons (strcat (strcase (car x)) "|*") (cdr x))))
           xrefNameColorList
   )
 )
)

(_xrefLayerColorChange
 '(
   ("0618__AC" . 1)
   ("0618__BM" . 2)
   ("0618__CL" . 3)
   ("0618__EC" . 4)
   ("0618__FE" . 5)
   ("0618__FL" . 6)
   ("0618__FP" . 7)
   ("0618__GC" . 11)
   ("0618__HD" . 41)
   ("0618__HO" . 71)
   ("0618__HW" . 91)
   ("0618__MW" . 121)
   ("0618__PA" . 151)
   ("0618__RE" . 171)
   ("0618__RP" . 191)
   ("0618__SL" . 211)
   ("0618__TL" . 241)
   ("0618__ZA" . 222)
   ("0618__ZB" . 144)
   ("0618__ZC" . 30)
  )
)

Posted

Trouble is the xref name will chage for every drawing I have to review so while this list is 0618 the next will be 0619 etc. etc.. and i have 1715 drawings :o

Posted
Trouble is the xref name will chage for every drawing I have to review so while this list is 0618 the next will be 0619 etc. etc.. and i have 1715 drawings :o
Are the xref names (0619, 0618) determined by the corresponding drawing name?
Posted

Hi Alanjt

 

they are determined by the xref drawing name yes. the only true constistency for them is the suffix they will always be (_AC,_BM etc...) but the number code can change

Posted

Are the suffixes consistent?

 

If so, perhaps something like:

([color=BLUE]defun[/color] c:xc ( [color=BLUE]/[/color] n )
   ([color=BLUE]vlax-for[/color] l ([color=BLUE]vla-get-layers[/color] ([color=BLUE]vla-get-activedocument[/color] ([color=BLUE]vlax-get-acad-object[/color])))
       ([color=BLUE]if[/color] ([color=BLUE]wcmatch[/color] ([color=BLUE]setq[/color] n ([color=BLUE]strcase[/color] ([color=BLUE]vla-get-name[/color] l))) [color=MAROON]"*|*"[/color])
           ([color=BLUE]vl-some[/color]
              '([color=BLUE]lambda[/color] ( x )
                   ([color=BLUE]if[/color] ([color=BLUE]wcmatch[/color] n ([color=BLUE]car[/color] x))
                       ([color=BLUE]progn[/color] ([color=BLUE]vla-put-color[/color] l ([color=BLUE]cdr[/color] x)) [color=BLUE]t[/color])
                   )
               )
              '(
                   ([color=MAROON]"*AC*"[/color] . 001)
                   ([color=MAROON]"*BM*"[/color] . 002)
                   ([color=MAROON]"*CL*"[/color] . 003)
                   ([color=MAROON]"*EC*"[/color] . 004)
                   ([color=MAROON]"*FE*"[/color] . 005)
                   ([color=MAROON]"*FL*"[/color] . 006)
                   ([color=MAROON]"*FP*"[/color] . 007)
                   ([color=MAROON]"*GC*"[/color] . 011)
                   ([color=MAROON]"*HD*"[/color] . 041)
                   ([color=MAROON]"*HO*"[/color] . 071)
                   ([color=MAROON]"*HW*"[/color] . 091)
                   ([color=MAROON]"*MW*"[/color] . 121)
                   ([color=MAROON]"*PA*"[/color] . 151)
                   ([color=MAROON]"*RE*"[/color] . 171)
                   ([color=MAROON]"*RP*"[/color] . 191)
                   ([color=MAROON]"*SL*"[/color] . 211)
                   ([color=MAROON]"*TL*"[/color] . 241)
                   ([color=MAROON]"*ZA*"[/color] . 222)
                   ([color=MAROON]"*ZB*"[/color] . 144)
                   ([color=MAROON]"*ZC*"[/color] . 030)
               )
           )
       )
   )
   ([color=BLUE]princ[/color])
)
([color=BLUE]vl-load-com[/color]) ([color=BLUE]princ[/color])

EDIT: I see you just answered that question...

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