You can freeze layers to speed up display changes, improve object selection performance, and reduce regeneration time for complex drawings. AutoCAD does not display, plot, or regenerate objects on frozen layers. Freeze the layers that you will not be working with for long periods of time. When you “thaw” a frozen layer, AutoCAD regenerates and displays the objects on that layer.
用户可以冻结图层以加快显示改变的速度,提高对象选择性能,以及减少复杂图形的重生成时间。AutoCAD 不会显示、打印或重生成冻结图层上的对象。可以冻结长时间不需要显示的图层。在“解冻”冻结的图层时,AutoCAD 将重新生成并显示该图层上的对象。
Use the IsFrozen property to freeze or thaw a layer. If you input a value of TRUE, the layer is frozen. If you input a value of FALSE, the layer is thawed.
要冻结或解冻图层,请使用 IsFrozen 特性。如果为此特性输入 TRUE,将冻结图层;如果输入 FALSE,将解冻图层。
This example creates a new layer called “ABC” and then freezes the layer.
本例创建一个新图层命名为“ABC”然后冻结这个图层。
Imports Autodesk.AutoCAD.Runtime
Imports Autodesk.AutoCAD.ApplicationServices
Imports Autodesk.AutoCAD.DatabaseServices
<CommandMethod("FreezeLayer")> _
Public Sub FreezeLayer()
'' 获得当前文档和数据库 Get the current document and database
Dim acDoc As Document = Application.DocumentManager.MdiActiveDocument
Dim acCurDb As Database = acDoc.Database
''启动一个事务 Start a transaction
Using acTrans As Transaction = acCurDb.TransactionManager.StartTransaction()
'' 以只读方式打开图层表 Open the Layer table for read
Dim acLyrTbl As LayerTable
acLyrTbl = acTrans.GetObject(acCurDb.LayerTableId, _
OpenMode.ForRead)
Dim sLayerName As String = "ABC"
Dim acLyrTblRec As LayerTableRecord
If acLyrTbl.Has(sLayerName) = False Then
acLyrTblRec = New LayerTableRecord()
''为一个图层指定一个名字 Assign the layer a name
acLyrTblRec.Name = sLayerName
''升级一个层表为可写 Upgrade the Layer table for write
acLyrTbl.UpgradeOpen()
'' 追加一个新的图层到层表和事务中 Append the new layer to the Layer table and the transaction
acLyrTbl.Add(acLyrTblRec)
acTrans.AddNewlyCreatedDBObject(acLyrTblRec, True)
Else
acLyrTblRec = acTrans.GetObject(acLyrTbl(sLayerName), _
OpenMode.ForWrite)
End If
'' 冻结图层 Freeze the layer
acLyrTblRec.IsFrozen = True
''保存更改并销毁事务 Save the changes and dispose of the transaction
acTrans.Commit()
End Using
End Sub
using Autodesk.AutoCAD.Runtime;
using Autodesk.AutoCAD.ApplicationServices;
using Autodesk.AutoCAD.DatabaseServices;
[CommandMethod("FreezeLayer")]
public static void FreezeLayer()
{
// 获得当前文档和数据库 Get the current document and database
Document acDoc = Application.DocumentManager.MdiActiveDocument;
Database acCurDb = acDoc.Database;
// 启动一个事务 Start a transaction
using (Transaction acTrans = acCurDb.TransactionManager.StartTransaction())
{
// 以只读方式打开图层表 Open the Layer table for read
LayerTable acLyrTbl;
acLyrTbl = acTrans.GetObject(acCurDb.LayerTableId,
OpenMode.ForRead) as LayerTable;
string sLayerName = "ABC";
LayerTableRecord acLyrTblRec;
if (acLyrTbl.Has(sLayerName) == false)
{
acLyrTblRec = new LayerTableRecord();
// Assign the layer a name
acLyrTblRec.Name = sLayerName;
// Upgrade the Layer table for write
acLyrTbl.UpgradeOpen();
// Append the new layer to the Layer table and the transaction
acLyrTbl.Add(acLyrTblRec);
acTrans.AddNewlyCreatedDBObject(acLyrTblRec, true);
}
else
{
acLyrTblRec = acTrans.GetObject(acLyrTbl[sLayerName],
OpenMode.ForWrite) as LayerTableRecord;
}
// 冻结图层 Freeze the layer
acLyrTblRec.IsFrozen = true;
// Save the changes and dispose of the transaction
acTrans.Commit();
}
}