外部参照定義をアタッチ解除して、外部参照を図面から完全に除去できます。また、個々の外部参照インスタンスを削除することもできます。外部参照定義をアタッチ解除すると、その外部参照に関連付けられたすべての従属シンボルが削除されます。外部参照のすべてのインスタンスが図面から削除された場合、AutoCAD は次回図面が開かれたときに外部参照定義を除去します。
外部参照をアタッチ解除するには、DetachXref メソッドを使用します。 ネストした外部参照をアタッチ解除することはできません。
次の例では、外部参照をいったんアタッチしてから、アタッチ解除します。この例では、Sample フォルダにある Exterior Elevations.dwg ファイルを使用します。このイメージが存在しない場合や、別のフォルダにある場合は、有効なパスおよびファイル名を指定してください。
Imports Autodesk.AutoCAD.Runtime Imports Autodesk.AutoCAD.ApplicationServices Imports Autodesk.AutoCAD.DatabaseServices Imports Autodesk.AutoCAD.Geometry <CommandMethod("DetachingExternalReference")> _ Public Sub DetachingExternalReference() ' Get the current database and start a transaction Dim acCurDb As Autodesk.AutoCAD.DatabaseServices.Database acCurDb = Application.DocumentManager.MdiActiveDocument.Database Using acTrans As Transaction = acCurDb.TransactionManager.StartTransaction() ' Create a reference to a DWG file Dim PathName As String = "C:\AutoCAD\Sample\Sheet Sets\Architectural\Res\Exterior Elevations.dwg" Dim acXrefId As ObjectId = acCurDb.AttachXref(PathName, "Exterior Elevations") ' If a valid reference is created then continue If Not acXrefId.IsNull Then ' Attach the DWG reference to the current space Dim insPt As New Point3d(1, 1, 0) Using acBlkRef As New BlockReference(insPt, acXrefId) Dim acBlkTblRec As BlockTableRecord acBlkTblRec = acTrans.GetObject(acCurDb.CurrentSpaceId, OpenMode.ForWrite) acBlkTblRec.AppendEntity(acBlkRef) acTrans.AddNewlyCreatedDBObject(acBlkRef, True) End Using MsgBox("The external reference is attached.") acCurDb.DetachXref(acXrefId) MsgBox("The external reference is detached.") End If ' Save the new objects to the database acTrans.Commit() ' Dispose of the transaction End Using End Sub
using Autodesk.AutoCAD.Runtime; using Autodesk.AutoCAD.ApplicationServices; using Autodesk.AutoCAD.DatabaseServices; using Autodesk.AutoCAD.Geometry; [CommandMethod("DetachingExternalReference")] public void DetachingExternalReference() { // Get the current database and start a transaction Database acCurDb; acCurDb = Application.DocumentManager.MdiActiveDocument.Database; using (Transaction acTrans = acCurDb.TransactionManager.StartTransaction()) { // Create a reference to a DWG file string PathName = "C:\\AutoCAD\\Sample\\Sheet Sets\\Architectural\\Res\\Exterior Elevations.dwg"; ObjectId acXrefId = acCurDb.AttachXref(PathName, "Exterior Elevations"); // If a valid reference is created then continue if (!acXrefId.IsNull) { // Attach the DWG reference to the current space Point3d insPt = new Point3d(1, 1, 0); using (BlockReference acBlkRef = new BlockReference(insPt, acXrefId)) { BlockTableRecord acBlkTblRec; acBlkTblRec = acTrans.GetObject(acCurDb.CurrentSpaceId, OpenMode.ForWrite) as BlockTableRecord; acBlkTblRec.AppendEntity(acBlkRef); acTrans.AddNewlyCreatedDBObject(acBlkRef, true); } Application.ShowAlertDialog("The external reference is attached."); acCurDb.DetachXref(acXrefId); Application.ShowAlertDialog("The external reference is detached."); } // Save the new objects to the database acTrans.Commit(); // Dispose of the transaction } }
Sub DetachingExternalReference() ' Define external reference to be inserted 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\Sample\Sheet Sets\Architectural\Res\Exterior Elevations.dwg" ' Add the external reference Set xrefInserted = ThisDrawing.ActiveLayout.Block. _ AttachExternalReference(PathName, "Exterior Elevations", insertionPnt, 1, 1, 1, 0, False) 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." End Sub