若要卸载外部参照,请使用以下方法。卸载当前图形中未使用的参照文件时,由于不必读取和显示不必要的图形几何图形或符号表信息,因此 AutoCAD 性能得到增强。在重新加载外部参照之前,外部参照几何和任何嵌套外部参照的几何图形不会显示在当前图形中。Unload 卸载外部参照定义此示例附加外部参照,然后卸载外部参照。此示例使用在 Sample 目录中找到的 Exterior Elevations.dwg 文件。如果您没有此映像,或者它位于其他目录中,请插入有效的路径和文件名。 VB.NETImports Autodesk.AutoCAD.Runtime
Imports Autodesk.AutoCAD.ApplicationServices
Imports Autodesk.AutoCAD.DatabaseServices
Imports Autodesk.AutoCAD.Geometry
<CommandMethod("UnloadingExternalReference")> _
Public Sub UnloadingExternalReference()
' 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.")
Using acXrefIdCol As New ObjectIdCollection
acXrefIdCol.Add(acXrefId)
acCurDb.UnloadXrefs(acXrefIdCol)
End Using
MsgBox("The external reference is unloaded.")
End If
' Save the new objects to the database
acTrans.Commit()
' Dispose of the transaction
End Using
End Sub
C#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
}
}
VBA/ActiveX 代码参考Sub UnloadingExternalReference()
' 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."
' Unload the external reference definition
ThisDrawing.Blocks.Item(xrefInserted.name).Unload
MsgBox "The external reference is unloaded."
End Sub
父主题: |
|Archiver|CAD开发者社区
( 苏ICP备2022047690号-1 苏公网安备32011402011833)
GMT+8, 2025-10-29 07:07
Powered by Discuz! X3.4
Copyright © 2001-2021, Tencent Cloud.