1.5、Freeze and Thaw Layers冻结和解冻图层
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属性来冻结或解冻一个图层。IsFrozen属性值为TRUE则冻结图层,IsFrozen属性值为FALSE则解冻图层。
Freeze a layer 冻结图层
This example creates a new layer called “ABC” and then freezes the layer.
本例创建一个名为“ABC”的新图层,然后将其冻结。
VB.NET
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
C#
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();
}
}
VBA/ActiveX Code Reference
Sub FreezeLayer()
' Create a new layer called "ABC"
Dim layerObj As AcadLayer
Set layerObj = ThisDrawing.Layers.Add("ABC")
' Freeze layer "ABC"
layerObj.Freeze = True
End Sub