CAD开发者社区

 找回密码
 立即注册

QQ登录

只需一步,快速开始

ObjectARX 开发指南

使层成为当前层 (.NET)

2023-1-1 13:30| 发布者: admin| 查看: 898| 评论: 0|来自: AutoCAD

您始终在活动图层上绘制。激活图层时,将在该图层上创建新对象。如果激活其他图层,则创建的任何新对象都将被指定为该新活动图层,并使用其颜色和线型。如果图层被冻结,则无法将其激活。

要激活图层,请使用对象的属性或 CLAYER 系统变量。例如:ClayerDatabase

使层通过数据库成为当前层

此示例使用属性设置通过对象的层电流。DatabaseClayer

VB.NET

Imports Autodesk.AutoCAD.Runtime
Imports Autodesk.AutoCAD.ApplicationServices
Imports Autodesk.AutoCAD.DatabaseServices
 
<CommandMethod("SetLayerCurrent")> _
Public Sub SetLayerCurrent()
    '' 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 = "Center"

        If acLyrTbl.Has(sLayerName) = True Then
            '' Set the layer Center current
            acCurDb.Clayer = acLyrTbl(sLayerName)

            '' Save the changes
            acTrans.Commit()
        End If

        '' Dispose of the transaction
    End Using
End Sub

C#

using Autodesk.AutoCAD.Runtime;
using Autodesk.AutoCAD.ApplicationServices;
using Autodesk.AutoCAD.DatabaseServices;
 
[CommandMethod("SetLayerCurrent")]
public static void SetLayerCurrent()
{
    // 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 = "Center";

        if (acLyrTbl.Has(sLayerName) == true)
        {
            // Set the layer Center current
            acCurDb.Clayer = acLyrTbl[sLayerName];

            // Save the changes
            acTrans.Commit();
        }

        // Dispose of the transaction
    }
}

VBA/ActiveX 代码参考

ThisDrawing.ActiveLayer = ThisDrawing.Layers("Center")

使用 CLAYER 系统变量使层成为电流

此示例使用 CLAYER 系统变量设置层电流。

VB.NET

Application.SetSystemVariable("CLAYER", "Center")

C#

Application.SetSystemVariable("CLAYER", "Center");

VBA/ActiveX 代码参考

ThisDrawing.SetVariable "CLAYER", "Center"

路过

雷人

握手

鲜花

鸡蛋

最新评论

QQ|Archiver|CAD开发者社区 ( 苏ICP备2022047690号-1 )

GMT+8, 2024-5-19 13:12

Powered by Discuz! X3.4

Copyright © 2001-2021, Tencent Cloud.

返回顶部