Detach Xrefs
 
 
 

You can detach an xref definition to remove the xrefs completely from your drawing. You can also erase the individual xref instances. Detaching the xref definition removes all dependent symbols associated with that xref. If all the instances of an xref are erased from the drawing, AutoCAD removes the xref definition the next time the drawing is opened.

To detach an xref, use the Detach method. You cannot detach a nested xref.

Detach an xref definition

This example attaches an external reference and then detaches 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_DetachingExternalReference()
	On Error GoTo ERRORHANDLER


	' Define external reference to be inserted
	Dim xrefHome As AcadBlock
	Dim xrefInserted As AcadExternalReference
	Dim insertionPnt(0 To 2) As Double
	Dim PathName As String
	insertionPnt(0) = 1
	insertionPnt(1) = 1
	insertionPnt(2) = 0
	PathName = "c:/AutoCAD 2008/sample/3D House.dwg"


	' Add the external reference
	Set xrefInserted = ThisDrawing.ModelSpace. _
			AttachExternalReference(PathName, "XREF_IMAGE", _
			insertionPnt, 1, 1, 1, 0, False)
	ZoomAll
	MsgBox "The external reference is attached."


	' Detach the external reference definition
	Dim name As String
	name = xrefInserted.name
	ThisDrawing.Blocks.Item(name).Detach
	MsgBox "The external reference is detached."
	Exit Sub
ERRORHANDLER:
	MsgBox Err.Description
End Sub