View Full Version : 2014 See updated Layer changes from a saved, reloaded X-Ref
tim_newsome
2017-11-06, 04:57 PM
I changed a color in my base file and went to the file it is attached to make the change there too and when I reloaded the X Ref to update for other saved changes the color also updated.
What variable setting allowed that to happen. I am so use to having to make layer color changes twice (once in the base and then once in the sheet.dwg its attached to) because the layer changes don't update.
cadtag
2017-11-06, 05:23 PM
visretain ,, set to 1 normally
I changed a color in my base file and went to the file it is attached to make the change there too and when I reloaded the X Ref to update for other saved changes the color also updated.
What variable setting allowed that to happen. I am so use to having to make layer color changes twice (once in the base and then once in the sheet.dwg its attached to) because the layer changes don't update.
the variable "visretain" is what you are talking about, 1 locks the changes, 0 ignores the changes.
So you can just change the layer setting in the file with the xref and it should hold.
Or change the base file layer settings, go in to your file with the xref, set visretain to 0, reload the xref (so it updates per the base file) and then set visretain to 1 to lock it in.
HTH
(to clarify, setting visretain to 0, simply shows the xref as the base file as it was saved last)
tim_newsome
2017-11-07, 06:09 PM
OK, I can clarify more descriptively whats baffling me.
I get the visretain = 1 for layer changes to update in the X-Ref. Standard procedure at all companies I have been at in ten years attach a base.dwg to another dwg that is simply for the purpose of a sheet with viewport & border. If I have not manipulated any layers through the viewport can I get the viewport to update layer changes from the saved Xref?
Iceberg
2017-11-07, 06:10 PM
Remember if you do any other changes in the drawing like freeze layers, turn layers off, they will update when you refresh the drawing, and undo some of the layer changes you have made in the main drawing. Just be careful.
BlackBox
2017-11-07, 06:22 PM
FWIW, I saw this thread yesterday which reminded me that I've been wanting to do this for a long while (from previous discussions with cadtag, as it happens Haha). :mrgreen:
I had already coded a 'Restore XREF' routine, which automagically handles stores/sets VISRETAIN, reloads the selected XREF(s), then restores VISRETAIN. This inherently reloads ALL layers in the selected XREF(s).
So, last night (somewhere around +/- 1:30 AM?) I took my 'Change Layer Color Nested' routine and began porting it over for the purposes of posting it here... It's working, but I didn't have time to finish a couple of things before going to bed, like accounting for when an XREF is already open by someone else (ObjectDBX doesn't like that), and when an XREF is already open by YOU (pulling the needed layer properties from THAT Document in Document Collection, in lieu of using ODBX at all), etc.
Mostly done, but need to get a couple of project submittals out before I can get back to it... More to come.
Cheers
OK, I can clarify more descriptively whats baffling me.
I get the visretain = 1 for layer changes to update in the X-Ref. Standard procedure at all companies I have been at in ten years attach a base.dwg to another dwg that is simply for the purpose of a sheet with viewport & border. If I have not manipulated any layers through the viewport can I get the viewport to update layer changes from the saved Xref?
Hello Tim,
Just to clarify my reply and maybe will help answer your question, problem.
I know it depends on your company's standards and procedures on how files are handled, but it usually goes like this (for most of my professional career anyway):
You have a "Base.dwg" that contains all the geometry that is usually used across disciplines. The "Base.dwg" is created using some sort of cad standards with layer names and colors etc.
The layers and linetypes in the "Base.dwg" are usually all "set" and aren't messed with, maybe new layers are added, but usually are there anyway because of a template that is used that has them all.
Then you create "Arch Sheet.dwg", which is a sheet drawing you have xreffed "Base.dwg" in, and for the most part, all the layers are correct, you may freeze some that you don't want or something.
This is the file you set visretain = 1, so everything is the way you want it next time you open it. (If you have visretain set to 0, it will forget what you changed and simply reload the "Base.dwg" how it was saved last, usually not what you want).
Similarly you create "Mech sheet.dwg" and have xreffed the "Base.dwg" file in, but you want to control the layers more, so you go into the layer manager and change the (XREF) layers to grey scale so your mech stuff shows up better, again this will have visretain =1 locking in your settings for that drawing.
At no time in any of this do you change the settings in the "Base.dwg" file to accommodate a sheet drawing, unless you really want to.
Sometimes I want to "reset" a sheet file to match the base file, so I will set visretain = 0 in the sheet file, and reload the xref and the xref updates matching the base file, then remember to set visretain back to 1.
Hope this helps..
(disclaimer.. this is assuming that everything is set to ByLayer, colors, linetypes etc, not easily handled though layer manager on an XREF)
I think Black Box is working on a little lisp-diddy that could help fix that sort of stuff.
BlackBox
2017-11-07, 08:47 PM
I think Black Box is working on a little lisp-diddy that could help fix that sort of stuff.
Roger that. (https://i.pinimg.com/736x/ad/28/fa/ad28fabaca87351357b0e487a731952c--military-quotes-military-humor.jpg)
BlackBox
2017-11-08, 05:42 AM
In the spirit of using the right tool for the job, here are a few of the routines I use for my own work, and one new one, that you may find useful.
Let me know if you can break anything, so I can try and mitigate any issue(s) you discover.
Change Layer Color:
This routine will allow user to select multiple layers, select a standard color, and then apply the color to the selected layers.
(vl-load-com)
(defun c:CLC () (c:ChangeLayerColor))
(defun c:ChangeLayerColor
(/ *error* ss color acDoc oLayers oLayer layers regen)
(princ "\rCHANGELAYERCOLOR ")
(defun *error* (msg)
(if acDoc
(progn
(vla-endundomark acDoc)
(if regen
(vla-regen acDoc acAllViewports)
)
)
)
(cond ((not msg)) ; Normal exit
((member msg '("Function cancelled" "quit / exit abort"))) ; <esc> or (quit)
((princ (strcat " ** Error: " msg " ** ")))
) ; Fatal error, display it
(princ)
)
(if (not (setq ss (ssget "_i")))
(progn
(prompt "\nSelect entity on layer to change color: ")
(setq ss (ssget))
)
)
(if (= 1 (sslength ss))
(setq color
(cdr
(assoc 62
(tblsearch "layer"
(cdr (assoc 8 (entget (ssname ss 0))))
)
)
)
)
)
(if
(and ss
(princ "\nSelect replacement layer color: ")
(setq color (acad_colordlg
(if color
color
1
)
nil
)
)
)
(progn
(vla-startundomark
(setq acDoc (vla-get-activedocument (vlax-get-acad-object)))
)
(setq oLayers (vla-get-layers acDoc))
(vlax-for x (setq ss (vla-get-activeselectionset acDoc))
(if
(not
(vl-position
(setq oLayer (vla-item oLayers (vla-get-layer x)))
layers
)
)
(setq layers (cons oLayer layers))
)
)
(vla-delete ss)
(foreach oLayer layers
(if (or regen
(= :vlax-true (vla-get-lock oLayer))
)
(setq regen T)
)
(vla-put-color oLayer color)
(vla-put-lineweight oLayer aclnwtbylwdefault)
)
)
)
(*error* nil)
)
Change Layer Color Nested:
This routine will allow user to select multiple nested layers, select a standard color, and then apply the color to the selected nested layers. This routine also works on layers nested within blocks in the active document, similar to XLIST Command reporting layer.
(vl-load-com)
(defun c:CLCN () (c:ChangeLayerColorNested))
(defun c:ChangeLayerColorNested
(/ *error* entity layer layers color acDoc oLayers oLayer)
(princ "\rCHANGELAYERCOLORNESTED ")
(defun *error* (msg)
(if acDoc
(progn
(vla-endundomark acDoc)
(vla-regen acDoc acAllViewports)
)
)
(cond ((not msg)) ; Normal exit
((member msg '("Function cancelled" "quit / exit abort"))) ; <esc> or (quit)
((princ (strcat " ** Error: " msg " ** ")))
) ; Fatal error, display it
(princ)
)
(while
(/= nil
(setq entity
(nentsel
"\nSelect nested entity to change layer color: "
)
)
)
(if
(not
(vl-position
(setq layer
(if
(= "0" (setq layer (cdr (assoc 8 (entget (car entity))))))
(cdr (assoc 8 (entget (car (last entity)))))
layer
)
)
layers
)
)
(print (reverse (setq layers (cons layer layers))))
)
)
(if
(and
layers
(setq color
(if (= 1 (length layers))
(cdr (assoc 62 (tblsearch "layer" (car layers))))
1
)
)
(princ "\nSelect replacement layer color: ")
(setq color (acad_colordlg color nil))
)
(progn
(vla-startundomark
(setq acDoc (vla-get-activedocument (vlax-get-acad-object)))
)
(setq oLayers (vla-get-layers acDoc))
(foreach layer layers
(vla-put-color (setq oLayer (vla-item oLayers layer)) color)
(vla-put-lineweight oLayer aclnwtbylwdefault)
)
)
)
(*error* nil)
)
Unfortunately, AUGI forums require that I break this up into multiple posts... Part 2 to follow.
Cheers
BlackBox
2017-11-08, 05:51 AM
... And the continuation... Part 2:
Restore XREFs:
This routine will store/set VISRETAIN == 0, reload the selected XREF(s), then restore VISRETAIN.
(vl-load-com)
(defun c:RestoreXrefs (/ *error* acDoc oBlocks blockName xrefs visretain)
(princ "\rRESTOREXREFS ")
(defun *error* (msg)
(and visretain (setvar 'visretain visretain))
(if xrefs (vla-endundomark acDoc))
(cond ((not msg)) ; Normal exit
((member msg '("Function cancelled" "quit / exit abort"))) ; <esc> or (quit)
((princ (strcat "\n** Error: " msg " ** "))) ; Fatal error, display it
)
(princ)
)
(if (ssget "_:L" '((0 . "INSERT")))
(progn
(vla-startundomark
(setq acDoc (vla-get-activedocument (vlax-get-acad-object)))
)
(setq oBlocks (vla-get-blocks acDoc))
(vlax-for x (vla-get-activeselectionset acDoc)
(if
(and
(setq blockName (vla-get-effectivename x))
(setq x (vla-item oBlocks blockName))
(= :vlax-true (vla-get-isxref x))
)
(setq xrefs (cons x xrefs))
)
)
(if xrefs
(progn
(vla-startundomark acDoc)
(setq visretain (getvar 'visretain))
(setvar 'visretain 0)
(foreach x xrefs
(vla-reload x)
)
)
(prompt "\n** Invalid selection ** ")
)
)
)
(*error* nil)
)
Restore XREF Layers:
This routine allow user to select multiple nested layers, and conditionally restore the source layer's properties, either by using the Document if already open in current session's Document Collection, or using ObjectDBX (if not read-only), or simply report that the source Document is open, and report the owner (if accessible).
(vl-load-com)
(defun c:RestoreXrefLayers (/ *error* _Parser _dbxDoc
_AdsSecurityUtility entity layer layers
acApp oDocuments openDocs acDoc oBlocks
oLayers nomutt item l data xrefName oXref
path xDoc dbxDoc isReadOnly dwgName
layerName oLayer oAdsSecurityUtility owner
)
(princ "\rRESTOREXREFLAYERS ")
(defun *error* (msg)
(if nomutt
(setvar 'nomutt nomutt)
)
(prompt "\n")
(if acDoc
(progn
(vla-endundomark acDoc)
(vla-regen acDoc acAllViewports)
)
)
(if dbxDoc
(vlax-release-object dbxDoc)
)
(if oAdsSecurityUtility
(vlax-release-object oAdsSecurityUtility)
)
(cond ((not msg)) ; Normal exit
((member msg '("Function cancelled" "quit / exit abort"))) ; <esc> or (quit)
((princ (strcat " ** Error: " msg " ** ")))
) ; Fatal error, display it
(princ)
)
(defun _Parser (char string / i segments segment)
(while (setq i (vl-string-search char string))
(setq segments (cons (setq segment (substr string 1 i)) segments))
(setq string (substr string (+ 2 i)))
)
(reverse (cons string segments))
)
(defun _dbxDoc ()
(or dbxDoc
(setq dbxDoc (vla-getinterfaceobject
acApp
(strcat "ObjectDBX.AxDbDocument."
(substr (getvar 'acadver) 1 2)
)
)
)
)
dbxDoc
)
(defun _AdsSecurityUtility ()
(or oAdsSecurityUtility
(setq oAdsSecurityUtility
(vlax-get-or-create-object
"ADsSecurityUtility"
)
)
)
oAdsSecurityUtility
)
(while
(/= nil
(setq entity
(nentsel
"\nSelect XREF layer(s) to restore: "
)
)
)
(if
(and
(not
(vl-position
(setq layer
(if
(= "0"
(setq layer (cdr (assoc 8 (entget (car entity)))))
)
(cdr (assoc 8 (entget (car (last entity)))))
layer
)
)
layers
)
)
(wcmatch layer "*|*")
)
(print (reverse (setq layers (cons layer layers))))
(prompt "\n** Must pick an XREF layer ** ")
)
)
(setq acApp (vlax-get-acad-object))
(setq oDocuments (vla-get-documents acApp))
(vlax-for x oDocuments
(setq openDocs (cons (cons (vla-get-name x) x) openDocs))
)
(vla-startundomark
(setq acDoc (vla-get-activedocument acApp))
)
(setq oBlocks (vla-get-blocks acDoc))
(setq oLayers (vla-get-layers acDoc))
(princ "\nWorking, please wait...")
(princ)
(setq nomutt (getvar 'nomutt))
(setvar 'nomutt 1)
;; group layers by xref into data
(foreach item (vl-sort layers '>)
(if (setq l (assoc (car (setq item (_Parser "|" item))) data))
(if (not (vl-position (cadr item) (cdr l)))
(setq data
(subst (cons (car l) (cons (cadr item) (cdr l))) l data)
)
)
(setq data (cons (cons (car item) (cdr item)) data))
)
)
;; iterate data, opening each doc/xref, restoring each layer
(foreach item data
(setq xrefName (car item))
(setq layers (cdr item))
(if (setq oXref (vla-item oBlocks xrefName))
(progn
(setq path (vla-get-path oXref))
(setq path (findfile path))
(if
(or
(and
(setq xDoc (assoc (strcat (vl-filename-base path)
(vl-filename-extension path)
)
openDocs
)
)
(setq xDoc (cdr xDoc))
)
(and
(or dbxDoc (setq dbxDoc (_dbxDoc)))
(not
(setq isReadOnly
(vl-catch-all-error-p
(vl-catch-all-apply
'vla-open
(list dbxDoc (setq dwgName path))
)
)
)
)
(setq xDoc dbxDoc)
)
)
(vlax-for xLayer (vla-get-layers xDoc)
(if
(vl-position
(setq layerName (strcase (vla-get-name xLayer)))
layers
)
(progn
(setq oLayer
(vla-item oLayers (strcat xrefName "|" layerName))
)
(foreach x '(color description freeze layeron linetype
lineweight lock plottable ;| others? |;
)
(vlax-put oLayer x (vlax-get xLayer x))
)
(setvar 'nomutt 0)
(prompt
(strcat
"\n >> \""
(strcat xrefName "|" layerName)
"\" layer has been restored. "
)
)
(setvar 'nomutt 1)
)
)
)
(progn
(setvar 'nomutt 0)
(prompt
(strcat
"\n** Unable to open \""
xrefName
"\" using ODBX ** "
(if (setq owner
(vlax-get (vlax-invoke
(_AdsSecurityUtility)
'GetSecurityDescriptor path 1 1
)
'owner
)
)
(strcat
"\nThe drawing is already open, contact user \""
owner
"\""
)
"\nVerify the drawing is not open. "
)
)
)
(setvar 'nomutt 1)
)
)
)
)
)
(*error* nil)
)
Cheers
Powered by vBulletin® Version 4.2.5 Copyright © 2025 vBulletin Solutions Inc. All rights reserved.