Detach method example

Sub DetachXRef_Example()
    ' This example attaches an Xref to the active drawing.
    ' It then unloads and detaches it using the .Unload and  .Detach methods.
    Dim oXref As AcadExternalReference
    Dim PtOrg(0 To 2) As Double: PtOrg(0) = 20: PtOrg(0) = 20: PtOrg(2) = 0
    'Note: make sure to point to an existing dwg on your system...
    Dim sFullPath As String: sFullPath = "D:/a/Blocks2D/Meubels/BEPL06_dubbel.dwg"
    Set oXref = ThisDrawing.ModelSpace.AttachExternalReference(sFullPath, "BlockNameForXref", PtOrg, 1, 1, 1, 0, False)
    ZoomAll
    Dim sBuf As String
    sBuf = "The external reference  with path: " & vbCrLf
    sBuf = sBuf & sFullPath & vbCrLf
    sBuf = sBuf & "has been attached as " & oXref.Name
    MsgBox sBuf
    ' Unload the external reference
    ThisDrawing.Blocks.Item(oXref.Name).Unload
    MsgBox "The external reference has been unloaded."
    ' Detach the external reference
    ThisDrawing.Blocks.Item(oXref.Name).Detach
    MsgBox "The external reference has been detached."
End Sub

© Bricsys NV. All rights reserved.