外部参照をロード解除するには、Unload メソッドを使用します。現在の図面で使用されていない参照ファイルをロード解除すると、不必要な図面ジオメトリまたはシンボル テーブル情報を読み込み表示する必要がないので、AutoCAD のパフォーマンスが改善されます。外部参照ジオメトリおよびネストした外部参照は、外部参照が再ロードされるまで現在の図面には表示されません。
次の例では、外部参照をアタッチしてから、ロード解除します。この例では、Sample フォルダにある Exterior Elevations.dwg ファイルを使用します。このイメージが存在しない場合や、別のフォルダにある場合は、有効なパスおよびファイル名を指定してください。
using Autodesk.AutoCAD.Runtime;
using Autodesk.AutoCAD.ApplicationServices;
using Autodesk.AutoCAD.DatabaseServices;
using Autodesk.AutoCAD.Geometry;
[CommandMethod("UnloadingExternalReference")]
public void UnloadingExternalReference()
{
// 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.");
using (ObjectIdCollection acXrefIdCol = new ObjectIdCollection())
{
acXrefIdCol.Add(acXrefId);
acCurDb.UnloadXrefs(acXrefIdCol);
}
Application.ShowAlertDialog("The external reference is unloaded.");
}
// Save the new objects to the database
acTrans.Commit();
// Dispose of the transaction
}
}