CAD二次开发IFoxCAD框架系列(19)-图层操作

1. 根据名称查询指定的图层

查看层表中是否含有名为"MyLayer"的图层。

csharp 复制代码
         using var tr = new DBTrans();
            if(tr.LayerTable.Has("MyLayer"))
            {
                //要执行的操作
            }

2. 遍历图层名称

遍历图层表并打印每个图层的名字 。

csharp 复制代码
            using var tr = new DBTrans();
            tr.LayerTable.GetRecordNames().ForEach(action: (layname) => layname.Print());

3. 图层新增

创建一个名为"MyLayer"的图层,要求图层颜色为红色,线宽为 0.3mm,可打印。

csharp 复制代码
        [CommandMethod(nameof(createLayer))]
        public void createLayer()
        {
            using var tr = new DBTrans();
            tr.LayerTable.Add("MyLayer",it =>
            {
                it.Color = Color.FromColorIndex(ColorMethod.ByColor, 1);
                it.LineWeight = LineWeight.LineWeight030;
                it.IsPlottable = true;
            });
        }

4. 图层修改

查找名为"MyLayer"的图层,并将图层"MyLayer"的名称改为"MyLayer2",颜色改为 2 号色,设为不可打印。

csharp 复制代码
        [CommandMethod(nameof(updateLayer))]
        public void updateLayer()
        {
            using var tr = new DBTrans();
            if (tr.LayerTable.Has("MyLayer"))
            {
                tr.LayerTable.Change("MyLayer", lt => {
                    lt.Name = "MyLayer2";
                    lt.Color = Color.FromColorIndex(ColorMethod.ByAci, 2);
                    lt.IsPlottable = false;
                });
            }
        }

5. 图层删除

csharp 复制代码
using var tr = new DBTrans();
tr.LayerTable.Delete("0");// 删除图层 0
tr.LayerTable.Delete("Defpoints");// 删除图层Defpoints
tr.LayerTable.Delete("1");// 删除不存在的图层 1
tr.LayerTable.Delete("2");// 删除有图元的图层 2
tr.LayerTable.Delete("3");// 删除图层 3

强制删除图层

csharp 复制代码
using var tr = new DBTrans();
tr.LayerTable.Remove("2"); // 强制删除存在图元的图层 2

上面基本上涵盖了咱们对图层的基本操作,

相关推荐
神仙别闹1 小时前
基于C#+Mysql实现(界面)企业的设备管理系统
开发语言·mysql·c#
△曉風殘月〆5 小时前
.Net Gacutil工具(全局程序集缓存工具)使用教程
c#·.net·gac·gacutil
时光追逐者5 小时前
C#/.NET/.NET Core技术前沿周刊 | 第 5 期(2024年9.9-9.15)
microsoft·c#·.net·.netcore
太陈抱不动8 小时前
C#学习笔记(三)Visual Studio安装与使用
笔记·学习·c#
秋月的私语8 小时前
C#通过注册表实现记住上次打开路径
c#·html·xhtml
Z_W_H_17 小时前
【C#】vs2022 .net8
c#
c#上位机1 天前
C#回调函数
java·前端·c#
0224号比邻星1 天前
[C语言]第九节 函数一基础知识到高级技巧的全景探索
c语言·c#
△曉風殘月〆1 天前
C#命令行参数解析库System.CommandLine介绍
c#·命令行·cmd·命令行解析
阑梦清川1 天前
C#环境搭建和入门教程--vs2022之下
开发语言·c#