Revert Layer

Discussion in 'AutoCAD' started by JasonDavidson, Mar 24, 2005.

  1. Is there any way to revert a single xref dependent layer to it's pre-visretain state? I come across this problem a number of times. Someone makes changes to the color or linetype in an xref, and the sheets don't pick it up because of visretain. I don't want to toggle visretain because I'll lose all my other layer states specific to that sheet. Really I just need something that'll read the xref definition and update the layer's linetype/color. I tried it with the following code, but that doesn't work wither, since the xref definition loaded into memory has the layer table of the current drawing, not the parent xref.

    On a side note, I've always wanted AutoCAD to prompt me with layers that are new in an xref when I open a sheet drawing. This way I'm alerted that I may have to do some freezing or look into whether the new layer should be on.

    Any suggestions?

    (defun c:RevertLayer ( / )
    (setq ent (nentsel "\nSelect nested entity on target layer: ")
    xref (entget (caar (reverse ent)))
    xrefent (entget (car ent))
    xrefname (cdr (assoc 2 xref))
    xreflayer (cdr (assoc 8 xrefent))
    activedoc (vla-get-activedocument (vlax-get-acad-object))
    xrefdatabase (vla-get-xrefdatabase (vla-item (vla-get-blocks activedoc) xrefname))
    xreflayers (vla-get-layers xrefdatabase)
    );setq

    (vlax-for item xreflayers
    (if (= xreflayer (vla-get-name item))
    (setq return (list (vla-get-name item) (vla-get-color item) (vla-get-linetype item)))
    );if
    );vlax-for

    return

    );defun c:RevertLayer
     
    JasonDavidson, Mar 24, 2005
    #1
  2. JasonDavidson

    Shane-W Guest

    Off the top of my head it seems like using lisp to create a txt file of the parent xrefs layers linetypes, etc.

    when you open a drawing that has the xref in it read in the layer color linetype and set accordingly.

    You could code it to do it by specified layer.

    Or maybe have the xref open and vl-propogate the infor mation you need from the xref to the working drawing.

    just a couple of ideas
     
    Shane-W, Mar 24, 2005
    #2
  3. JasonDavidson

    Joe Burke Guest

    Jason,

    Here's what I use. It's designed to do what you asked.

    It's not what it should be if you happen to pick an object in an xref on layer zero
    or defpoints. But it met my needs at the time.

    I haven't used it much since, so it hasn't had much testing. Let me know if you find
    any problems.

    ;; Joe Burke 4/13/2004
    ;; update the selected xref layer color and linetype in the
    ;; active file from xref source file
    (defun c:XrefReloadLayer ( / *Error* *acad* doc documents layers elst vobj
    layname layobj pos xlayname xblk xblkname path
    xdoc xlayers xlayobj xclr xltyp )

    (defun *Error* (Msg)
    (cond
    ((or (not Msg)
    (member Msg '("console break"
    "Function cancelled"
    "quit / exit abort"))))
    ((princ (strcat "\nError: " Msg)))
    )
    (princ)
    )

    (setq *acad* (vlax-get-acad-object)
    doc (vla-get-activedocument *acad*)
    documents (vla-get-Documents *acad*)
    layers (vla-get-Layers doc)
    )
    (while
    (or
    (not (setq elst (nentsel "\nSelect object on xref layer: ")))
    (not (eq 'ENAME (type (last (last elst)))))
    (not (vlax-property-available-p
    (vlax-ename->vla-object (last (last elst))) 'Path))
    )
    (princ "\nMissed pick or xref not selected: ")
    )
    (and
    (setq vobj (vlax-ename->vla-object (car elst)))
    (setq layname (vlax-get vobj 'Layer))
    (if (equal "0" layname) ;obj is probably in a block
    (progn
    (setq vobj (vlax-ename->vla-object (car (last elst))))
    (setq layname (vlax-get vobj 'Layer))
    )
    T
    )
    (setq layobj (vla-item layers layname))
    (if (not (vl-string-search "|" layname))
    (progn
    (princ "\nCannot determine xref layer name... exiting. ")
    (exit)
    )
    T
    )
    (setq pos (vl-string-search "|" layname)
    xlayname (substr layname (+ 2 pos))
    xblk (vlax-ename->vla-object (last (last elst)))
    xblkname (vlax-get xblk 'Name)
    path (get-xref-path xblkname)
    xdoc (DocAtPath path)
    xlayers (vla-get-Layers xdoc)
    xlayobj (vla-item xlayers xlayname)
    xclr (vlax-get xlayobj 'Color)
    xltyp (vlax-get xlayobj 'Linetype)
    )
    (vlax-release-object xdoc)
    (not (vlax-put layobj 'Color xclr))
    (not (vlax-put layobj 'Linetype xltyp))
    ) ;and
    (vla-regen doc acActiveViewport)
    (princ (strcat "\nLayer name: " layname " reloaded. "))
    (*Error* nil)
    ) ;end

    ;shortcut
    (defun c:XRL () (c:XrefReloadLayer))

    ;; -----------------------------
    ;; argument: full path
    ;; returns a document object (srcdoc)
    ;; either an open document or an ODBX doc
    (defun DocAtPath ( path / *acad* documents srcdoc )
    (setq *acad* (vlax-get-acad-object)
    documents (vla-get-documents *acad*)
    )
    ;check the documents collection
    (vlax-for x documents
    (if (= path (vlax-get x 'FullName))
    (setq srcdoc x)
    )
    )
    ;if not in documents collection, use ObjectDBX
    (if (null srcdoc)
    (cond
    ((> (atoi (getvar "AcadVer")) 15)
    (setq srcdoc
    (vla-GetInterfaceObject *acad* "ObjectDBX.AxDbDocument.16"))
    (vla-open srcdoc path)
    )
    (T
    (if (not
    (vl-registry-read "HKEY_CLASSES_ROOT\\ObjectDBX.AxDbDocument\\CLSID"))
    (startapp "regsvr32.exe"
    (strcat "/s \"" (findfile "axdb15.dll") "\""))
    )
    (setq srcdoc (vla-GetInterfaceObject *acad* "ObjectDBX.AxDbDocument"))
    (vla-open srcdoc path)
    )
    )
    )
    srcdoc
    ) ;end
    ;; -----------------------------

    ;; -----------------------------
    ;; If an xref is not found in the saved path AutoCAD searches
    ;; the whole support path. By Stephan Koster 2001
    ;; argument: an xref block name
    ;; returns the full path to the xref if successful
    (defun get-xref-path (blockname / data path saved_path pos)
    (cond ((not (setq data (tblsearch "block" blockname))))
    ;; Does the block exist
    ((/= (logand (cdr (assoc 70 data)) 4) 4))
    ;; Is it an xref
    ((and (setq saved_path (cdr (assoc 1 data)))
    (setq path (findfile saved_path))
    ;; Can it be found on the saved path
    )
    )
    ((not (setq pos (vl-string-position (ascii "\\") saved_path 1 T))))
    (T (setq path (findfile (substr saved_path (+ pos 2)))))
    ;; Can it be found somewhere else in the search path
    )
    path
    )
    ;; -----------------------------
     
    Joe Burke, Mar 25, 2005
    #3
Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments (here). After that, you can post your question and our members will help you out.