Here is code that I came up with yesterday. I was just trying to get the xclip boundary, but then I went a step further and made it so you could change the type from overlay to attach, and vice versa. This is still in beta form, as I have only tested it with xrefs added in WCS, and only with one xref per, but I did check it with an xref whose path was not saved, and was not in the search path, and it found said xref file. The only problem is, is that it sets the xref path to the file path, and not just the file name like it was stored, so that might be an item to fix. I haven't tested it was relative pathing either. Post any comments / ideas / whatever.
(defun GetSpatialFilter (ename / Data Dict tempDict)
; Get the xclip boundry
(if
(and
(setq Data (entget ename))
(setq Dict (cdr (assoc 360 Data)))
(setq tempDict (dictsearch Dict "ACAD_FILTER"))
(setq tempDict (dictsearch (cdr (assoc -1 tempDict)) "SPATIAL"))
)
(cons '(0 . "SPATIAL_FILTER") (member (assoc 100 tempDict) tempDict))
)
)
(defun SetSpatialFilter (ename fltData / Data Dict tempDict tempList)
; Set the xclip boundry
(if
(and
(setq Data (entget ename))
(setq Dict
(if (setq tempList (assoc 360 Data))
(cdr tempList)
(entmakex '((0 . "DICTIONARY") (100 . "AcDbDictionary")))
)
)
(setq tempDict
(if (setq tempList (dictsearch Dict "ACAD_FILTER"))
(cdr (assoc -1 tempList))
(dictadd Dict "ACAD_FILTER" (entmakex '((0 . "DICTIONARY") (100 . "AcDbDictionary"))))
)
)
)
(progn
(dictremove tempDict "SPATIAL")
(dictadd tempDict "SPATIAL" (entmakex fltData))
(entmod
(if (setq tempList (assoc 360 Data))
(subst (cons 360 Dict) tempList Data)
(progn
(setq tempList (member (assoc 5 Data) (reverse Data)))
(append
(reverse tempList)
(append
(list
'(102 . "{ACAD_XDICTIONARY")
(cons 360 Dict)
'(102 . "}")
)
(member (assoc 5 Data) Data)
)
)
)
)
)
)
)
)
(defun GetCurrentXrefPath (doc fileName / FileDep cnt tempFd)
(setq FileDep (vla-get-FileDependencies doc))
(setq cnt 1)
(while (<= cnt (vla-get-Count FileDep))
(if
(and
(setq tempFd (vla-Item FileDep cnt))
(= (vla-get-Feature tempFd) "Acad:XRef")
(= (vla-get-FileName tempFd) fileName)
)
(setq cnt (1+ (vla-get-Count FileDep)))
(setq cnt (1+ cnt)
tempFd nil
)
)
)
(if tempFd
(vla-get-FullFileName tempFd)
)
)
(defun XrefType (doc xrObj bOverlay / tempEnt tempData InsList XrName XrPath tempXrObj tempXrEnt tempList BlkCol NewXrObj DidSwitch)
(if
(and
(setq tempEnt (vlax-vla-object->ename xrObj))
(setq tempData (entget tempEnt))
(setq InsList (member (assoc 331 tempData) tempData))
(setq InsList (cdr (member '(102 . "}") (reverse InsList))))
(setq tempData (entget (cdr (assoc 360 tempData))))
(setq XrName (cdr (assoc 2 tempData)))
(setq XrPath (cdr (assoc 1 tempData)))
(or
(findfile Xrpath)
(setq XrPath (GetCurrentXrefPath doc (strcat (vl-filename-base XrPath) (vl-filename-extension XrPath))))
)
)
(progn
(foreach i InsList
(setq tempData (entget (cdr i)))
(setq tempXrObj
(vlax-invoke
(vlax-ename->vla-object (cdr (assoc 330 tempData)))
'AttachExternalReference
XrPath
"TempXref"
(trans (cdr (assoc 10 tempData)) (cdr (assoc 210 tempData)) 0)
(cdr (assoc 41 tempData))
(cdr (assoc 42 tempData))
(cdr (assoc 43 tempData))
(cdr (assoc 50 tempData))
bOverLay
)
)
(vla-put-Layer tempXrObj (cdr (assoc 8 tempData)))
(vlax-put tempXrObj 'Normal (cdr (assoc 210 tempData)))
(setq tempXrEnt (vlax-vla-object->ename tempXrObj))
(if (setq tempList (GetSpatialFilter (cdr i)))
(SetSpatialFilter tempXrEnt tempList)
)
(if (not BlkCol)
(setq BlkCol (vla-get-Blocks doc))
)
(entdel (cdr i))
)
(vla-Detach xrObj)
(setq NewXrObj (vla-Item BlkCol "TempXref"))
(vla-put-Name NewXrObj XrName)
(setq DidSwitch T)
)
)
DidSwitch
)
Calling commands.
(defun c:ToggleXrefs (/ ActDoc Sel EntData BlkCol XrName BlkDef)
(setq ActDoc (vla-get-ActiveDocument (vlax-get-Acad-Object)))
(vla-EndUndoMark ActDoc)
(vla-StartUndoMark ActDoc)
(if
(and
(setq Sel (entsel "\n Select xref to toggle between overlay and attach: "))
(setq EntData (entget (car Sel)))
(= (cdr (assoc 0 EntData)) "INSERT")
(setq BlkCol (vla-get-Blocks ActDoc))
(setq XrName (cdr (assoc 2 EntData)))
(setq EntData (tblsearch "block" XrName))
(setq BlkDef (vla-Item BlkCol XrName))
(equal (vla-get-IsXref BlkDef) :vlax-true)
)
(if (equal (logand (cdr (assoc 70 EntData)) 8) 8)
(if (XrefType (vla-get-ActiveDocument (vlax-get-Acad-Object)) BlkDef 0)
(prompt (strcat "\n Success in making xref: " XrName ", an attached xref."))
)
(if (XrefType (vla-get-ActiveDocument (vlax-get-Acad-Object)) BlkDef 1)
(prompt (strcat "\n Success in making xref: " XrName ", an overlayed xref."))
)
)
)
(vla-EndUndoMark ActDoc)
(princ)
)
(defun c:MakeAttach (/ ActDoc Sel EntData BlkCol XrName BlkDef)
(setq ActDoc (vla-get-ActiveDocument (vlax-get-Acad-Object)))
(vla-EndUndoMark ActDoc)
(vla-StartUndoMark ActDoc)
(if
(and
(setq Sel (entsel "\n Select xref to toggle between overlay and attach: "))
(setq EntData (entget (car Sel)))
(= (cdr (assoc 0 EntData)) "INSERT")
(setq BlkCol (vla-get-Blocks ActDoc))
(setq XrName (cdr (assoc 2 EntData)))
(setq EntData (tblsearch "block" XrName))
(setq BlkDef (vla-Item BlkCol XrName))
(equal (vla-get-IsXref BlkDef) :vlax-true)
;(MakeAttach (vla-get-ActiveDocument (vlax-get-Acad-Object)) BlkDef)
(XrefType (vla-get-ActiveDocument (vlax-get-Acad-Object)) BlkDef 0)
)
(prompt (strcat "\n Success in making xref: " XrName ", an attached xref."))
)
(vla-EndUndoMark ActDoc)
(princ)
)
(defun c:MakeOverlay (/ ActDoc Sel EntData BlkCol XrName BlkDef)
(setq ActDoc (vla-get-ActiveDocument (vlax-get-Acad-Object)))
(vla-EndUndoMark ActDoc)
(vla-StartUndoMark ActDoc)
(if
(and
(setq Sel (entsel "\n Select xref to toggle between overlay and attach: "))
(setq EntData (entget (car Sel)))
(= (cdr (assoc 0 EntData)) "INSERT")
(setq BlkCol (vla-get-Blocks ActDoc))
(setq XrName (cdr (assoc 2 EntData)))
(setq EntData (tblsearch "block" XrName))
(setq BlkDef (vla-Item BlkCol XrName))
(equal (vla-get-IsXref BlkDef) :vlax-true)
;(MakeOverlay (vla-get-ActiveDocument (vlax-get-Acad-Object)) BlkDef)
(XrefType (vla-get-ActiveDocument (vlax-get-Acad-Object)) BlkDef 1)
)
(prompt (strcat "\n Success in making xref: " XrName ", an overlayed xref."))
)
(vla-EndUndoMark ActDoc)
(princ)
)