+ Reply to Thread
Results 1 to 5 of 5
  1. #1
    Junior Member jweber's Avatar
    Computer Details
    jweber's Computer Details
    Operating System:
    Windows
    Discipline
    Architectural
    jweber's Discipline Details
    Occupation
    Architect
    Discipline
    Architectural
    Using
    Architecture 2016
    Join Date
    Jun 2016
    Location
    Bozeman, MT
    Posts
    21

    Default Xref manipulation- changing layer colors + entities color to bylayer, etc.

    Registered forum members do not see this ad.

    First and foremost - credit for the following code goes to Mike.Perry @ http://forums.augi.com/showthread.ph...ll=1#post32836 and T.Willey @ http://forums.augi.com/showthread.ph...l=1#post719686

    Using the 2 aforementioned codes, I have written the following lisp to suit my needs= 1. allow multiple selected xref's to be affected 2. freeze a set list of layers in all selected xref's 3. turn all layer colors to 15, except for a few @ color 13 and 4. change all entities within the selected xrefs to color bylayer, but specifically omitting several nested xrefs (section cuts, grid).

    Code:
    (defun c:xr-elec (/ sset ctr xr2 xr3 xr4 xr5 xr6 tx1 xclr ocmd llist temp1 layfzn)
    ; Change all the layers of an xref to specified color.
      (vl-load-com)
      (setq ocmd (getvar "cmdecho"))
      (setvar "cmdecho" 0)
      (command "_.undo" "_end")
      (command "_.undo" "_group")
      (prompt "\nSelect xref(s) to convert to ELEC: ")
      (if (setq sset (ssget))
        (progn
          (setq ctr 0)
          (repeat (sslength sset)
            (setq xr1 (ssname sset ctr))
            (if xr1
              (progn
                (setq xr2 (entget xr1))
                (setq tx1 (cdr (assoc 0 xr2)))
                (if
                  (and
                    (= tx1 "INSERT")
      	        (setq xr3 (cdr (assoc 2 xr2)))
         	        (setq xr4 (tblsearch "block" xr3))
           	        (setq xr5 (cdr (assoc 1 xr4)))
         	      )
                  (progn
                    (setq xclr 15) ;;SET LAYER COLOR
                    (if (assoc 62 xr2)
                      (entmod (subst (cons 62 xclr) (assoc 62 xr2) xr2))
                      (entmod (append xr2 (list (cons 62 xclr))))
                    )
                    (setq xr6 (strcat xr3 "|"))
                    (setq llist (vla-get-layers (vla-get-activedocument (vlax-get-acad-object))))
                    (vlax-for item llist
                      (if (vl-string-search xr6 (vlax-get item 'Name))
                        (progn
                          (setq temp1 (vlax-get item 'TrueColor))
                          (vlax-put temp1 'ColorIndex (rtos xclr 2 0))
    	              (vlax-put item 'TrueColor temp1)
                        )
                      )
      	        )
    	        ;change all entities within xrefs to color bylayer, omitting <section,grid> nested xrefs
    	        (command "_.xref" "unload" "section*,grid")
                    (blocksbylayer xr1)
    	        (command "_.xref" "reload" "section*,grid")
                  )
                (prompt "\nNot an xref"))
              )
            )
          (setq ctr (1+ ctr)))
        ) (princ) 
      ) 
      (command "_.undo" "_end")
      ;freeze list of layers
      (setq layfzn "0,*|AREA,*|DIM*,*|DOOR TAG*,*|KEY NOTES,*|LINE-CENTER,*|NO PLOT,
    	     *|POCHE-FLOOR*,*|SYMBOL-*,*|SYMBOL_*,*|SYMBOL *,*|TEXT*,*|WINDOW TAG*,*|SECTION CUTS-96,
    	     *|GRID-96")
      (command "_.layer" "freeze" layfzn "")
      ;change a few specific layer colors
      (command "_.layer" "color" 13 "*|wall_shade,*|poche-roof*" "")
      (setvar "cmdecho" ocmd)
      (princ)
    )
    
    
    (defun blocksbylayer (xr1 / ELST ENAM ESEL BNAM FLST)
      (setq ELST (entget xr1)
            BNAM (cdr (assoc 2 ELST))
    	FLST nil
      )
      (fix1 BNAM)
      (vl-cmdf "regen")
      (princ)
    )
    
    
    (defun FIX1 (BNAM / BENAM)
      (if (not (member BNAM FLST))
        (progn
          (setq FLST  (cons BNAM FLST)
    	    BENAM (tblobjname "block" BNAM))
          (while
    	(setq BENAM (entnext BENAM))
     	;(print (entget BENAM))
            (if (= (cdr (assoc 0 (entget BENAM))) "INSERT")
              (fix1 (cdr (assoc 2 (entget BENAM))))
              (vla-put-color (vlax-ename->vla-object BENAM) 256)
            )
          )
        )
      )
    )
    HERE'S my problem- the code to change entities (blocks) to color by layer, both the original posted by Mike.Perry, and the modified code within my lisp (defun blocksbylayer) --do what they're intended to do---UNTIL closing and reopening the file I'm working on, at which point all entities which were changed to color bylayer, are back to the forced colors.... I'm baffled as to the cause.

    I'm clearly not a savant at writing code, but I want to learn and hate just blindly asking for help- hence the hack and merge approach, but I've reached a point with this project where I'm truly out of ideas, so any and all advice is welcome. Thanks.

  2. #2
    Senior Member Jef!'s Avatar
    Using
    AutoCAD 2008
    Join Date
    Sep 2010
    Posts
    212

    Default

    Hi there!

    From time to time I look for unanswered threads, and try to help out. Better late than never they say.

    both (...) lisp (...) do what they're intended to do---UNTIL closing and reopening the file I'm working on, at which point all entities which were changed to color bylayer, are back to the forced colors.... I'm baffled as to the cause.
    Sounds to me like your system variable visretain is set to 0, and you need to set it to 1. Visretain controls the lt, colors, lw, visibility and plot style of x-ref dependant layers. If visretain is set to 0, any change will only remain in the current session. Reopening the container dwg will reload the layer settings from the xref. If visretain is set to 1, then any changes to layer settings of x-ref dependant layers will be saved in the container drawing, and persist if it is closed and reopened.

    I hope it helps.
    Different goal also quite often means different path...

  3. #3
    Junior Member jweber's Avatar
    Computer Details
    jweber's Computer Details
    Operating System:
    Windows
    Discipline
    Architectural
    jweber's Discipline Details
    Occupation
    Architect
    Discipline
    Architectural
    Using
    Architecture 2016
    Join Date
    Jun 2016
    Location
    Bozeman, MT
    Posts
    21

    Default

    Hey Jeff, thanks for the reply.

    After this post, and a lot more digging, using code to force entities within an xref to color bylayer only lasts until the xref is reloaded, either by closing and reopening, or manually in the xref manager. No way around it.

    That said, autocad has a new(er) system variable XREFOVERRIDE, which forces ALL entities in ALL xref's to color bylayer. Not very useful if you only want specific entities or specific xrefs to be color bylayer.

    I'd be glad to be corrected, but as I understand it, there's no way around it, at least for now. Thanks again for the reply.

  4. #4
    Senior Member Jef!'s Avatar
    Using
    AutoCAD 2008
    Join Date
    Sep 2010
    Posts
    212

    Default

    I'm currently on 2015, and have no XREFOVERRIDE variable. BUT if it is a variable that it can be changed, right?

    What I would try, in the container drawing,
    turn off XREFOVERRIDE
    set VISRETAIN to 1
    make your changes to the xref dependent layers
    save container drawing.

    All overrides made on xref dependent layers should be retained in the container drawing after closing and reopening the container drawing.
    Different goal also quite often means different path...

  5. #5
    Luminous Being Dadgad's Avatar
    Using
    AutoCAD 2013
    Join Date
    Nov 2011
    Location
    At the confluence of worthlessness & invaluability
    Posts
    5,891

    Default

    Registered forum members do not see this ad.

    Quote Originally Posted by Jef! View Post
    I'm currently on 2015, and have no XREFOVERRIDE variable. BUT if it is a variable that it can be changed, right?

    What I would try, in the container drawing,
    turn off XREFOVERRIDE
    set VISRETAIN to 1
    make your changes to the xref dependent layers
    save container drawing.

    All overrides made on xref dependent layers should be retained in the container drawing after closing and reopening the container drawing.
    +1 That sounds like a good approach to me.

    Jweber, barring that solving your problem, you might also want to use the SYSVDLG command to access all relevant variable options for XREFOVERRIDE, there may be some further options available.
    Volume and repetition do not validate opinions forged in the absence of thought.

Similar Threads

  1. changing (non bylayer) colors of X-ref drawing
    By freebutterflyx in forum AutoCAD Drawing Management & Output
    Replies: 6
    Last Post: 10th Jun 2015, 06:51 pm
  2. True Color layers changing Colors when XREF
    By RSantos in forum AutoCAD Drawing Management & Output
    Replies: 16
    Last Post: 15th Jan 2015, 07:55 pm
  3. Xref layer colors changing...
    By nnutting in forum AutoCAD 2D Drafting, Object Properties & Interface
    Replies: 2
    Last Post: 15th Feb 2014, 02:41 am
  4. Replies: 0
    Last Post: 7th Sep 2011, 12:59 pm
  5. problem with changing layer color in Xref title block
    By cadmando2 in forum CAD Management
    Replies: 4
    Last Post: 28th Jan 2009, 12:35 am

Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts