Jump to content

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


jweber

Recommended Posts

First and foremost - credit for the following code goes to Mike.Perry @ http://forums.augi.com/showthread.php?5547-Changing-block-entities-color-to-bylayer&p=32836&viewfull=1#post32836 and T.Willey @ http://forums.augi.com/showthread.php?62996-changing-xref-layer-colors&p=719686&viewfull=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).

 

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

Link to comment
Share on other sites

  • 1 month later...

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.

Link to comment
Share on other sites

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.

Link to comment
Share on other sites

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.

Link to comment
Share on other sites

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

 

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.

Link to comment
Share on other sites

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