Unload Xrefs
From AutoCAD ActiveX
To unload an xref, use the Unload method. When you unload a referenced file that is not being used in the current drawing, the AutoCAD performance is enhanced by not having to read and display unnecessary drawing geometry or symbol table information. The xref geometry and that of any nested xref is not displayed in the current drawing until the xref is reloaded.
This example attaches an external reference and then unloads the external reference. This example uses the 3D House.dwg file found in the sample directory. If you do not have this image, or if it is located in a different directory, insert a valid path and file name for the PathName variable.
Sub Ch10_UnloadingExternalReference()
On Error GoTo ERRORHANDLER
' Define external reference to be insertedDim xrefHome As AcadBlockDim xrefInserted As AcadExternalReferenceDim insertionPnt(0 To 2) As DoubleDim PathName As StringinsertionPnt(0) = 1insertionPnt(1) = 1insertionPnt(2) = 0PathName = "c:/AutoCAD 2009/sample/3D House.dwg"' Add the external referenceSet xrefInserted = ThisDrawing.ModelSpace. _AttachExternalReference(PathName, "XREF_IMAGE", _insertionPnt, 1, 1, 1, 0, False)ZoomAllMsgBox "The external reference is attached."' Unload the external reference definitionThisDrawing.Blocks.Item(xrefInserted.name).UnloadMsgBox "The external reference is unloaded."Exit SubERRORHANDLER:MsgBox Err.DescriptionEnd Sub