03-05 创建和编辑AutoCAD实体(五) 使用图层、颜色和线型(1)使用图层(1-5)

本文介绍如何使用AutoCAD通过冻结图层来提高图形显示速度、改善对象选择性能及减少复杂绘图的重生成时间。冻结图层后,图层上的对象将不被显示、打印或重生成。文中提供了使用IsFrozen属性冻结或解冻图层的方法,并展示了通过VB.NET、C#和VBA实现创建并冻结图层的示例代码。
 

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

 

评论
成就一亿技术人!
拼手气红包6.0元
还能输入1000个字符
 
红包 添加红包
表情包 插入表情
 条评论被折叠 查看
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值