CAD.NET二次开发 新建图层 删除图层 指定图层颜色以及线形等
基于浩辰CAD 2019测试 功能实现
直接上代码:
[CommandMethod("CreateAndAssignAlayer")] //新建图层 然后添加到图层表里
public static void CreateAndAssignAlyer()
{
Document doc = Application.DocumentManager.MdiActiveDocument;
Database db = doc.Database;
using (Transaction Trans = db.TransactionManager.StartTransaction())
{
//以读模式打开图层表
LayerTable layerTable;
layerTable = Trans.GetObject(db.LayerTableId, OpenMode.ForNotify) as LayerTable;
string sLayerName = "test1";
if (layerTable.Has(sLayerName) == false)
{
LayerTableRecord layerTableRecord = new LayerTableRecord();
layerTableRecord.Color = Color.FromColorIndex(ColorMethod.ByAci, 1);
layerTableRecord.Name = sLayerName;
layerTable.UpgradeOpen();
layerTable.Add(layerTableRecord);
Trans.AddNewlyCreatedDBObject(layerTableRecord, true);
}
BlockTable blockTable;
blockTable = Trans.GetObject(db.BlockTableId, OpenMode.ForRead) as BlockTable;
BlockTableRecord blockTableRecord;
blockTableRecord = Trans.GetObject(blockTable[BlockTableRecord.ModelSpace], OpenMode.ForWrite) as BlockTableRecord;
Circle circle = new Circle();
circle.Center = new Point3d(100, 200, 0);
circle.Radius = 300;
circle.Layer = sLayerName;
blockTableRecord.AppendEntity(circle);
Trans.AddNewlyCreatedDBObject(circle, true);
db.Clayer = layerTable[sLayerName];
Trans.Commit();
}
}
[CommandMethod("TurnLayerOff")] //关闭图层表
public void TurnLayerOff()
{
Document doc = Application.DocumentManager.MdiActiveDocument;
Database database = doc.Database;
using (Transaction trans = database.TransactionManager.StartTransaction())
{
LayerTable layerTable;
layerTable = trans.GetObject(database.LayerTableId, OpenMode.ForWrite) as LayerTable;
String slayer = "20180415";
LayerTableRecord layerTableRecord;
if (layerTable.Has(slayer) == false)
{
layerTableRecord = new LayerTableRecord();
layerTableRecord.Color = Color.FromColorIndex(ColorMethod.ByColor, 2);
layerTableRecord.Name = slayer;
layerTable.UpgradeOpen();
layerTable.Add(layerTableRecord);
trans.AddNewlyCreatedDBObject(layerTableRecord, true);
}
else
{
layerTableRecord = trans.GetObject(layerTable[slayer], OpenMode.ForWrite) as LayerTableRecord;
}
layerTableRecord.IsOff = true;
BlockTable blockTable;
blockTable = trans.GetObject(database.BlockTableId, OpenMode.ForRead) as BlockTable;
BlockTableRecord blockTableRecord = trans.GetObject(blockTable[BlockTableRecord.ModelSpace], OpenMode.ForWrite) as BlockTableRecord;
Circle cir = new Circle();
cir.Center = new Point3d(200, 300, 400);
cir.Radius = 500;
cir.Layer = slayer;
blockTableRecord.AppendEntity(cir);
trans.AddNewlyCreatedDBObject(cir, true);
trans.Commit();
}
}
[CommandMethod("FrozenLayer")]
public void FrozenLayer()
{
Document document = Application.DocumentManager.MdiActiveDocument;
Database database = document.Database;
using (Transaction transaction=database.TransactionManager.StartTransaction())
{
LayerTable layerTable;
layerTable = transaction.GetObject(database.LayerTableId,OpenMode.ForWrite) as LayerTable;
string aLayer = "test1";
LayerTableRecord layerTableRecord;
if (layerTable.Has(aLayer)==false)
{
layerTableRecord = new LayerTableRecord();
layerTableRecord.Color = Color.FromColorIndex(ColorMethod.ByAci,3);
layerTableRecord.Name = aLayer;
layerTable.UpgradeOpen();
layerTable.Add(layerTableRecord);
transaction.AddNewlyCreatedDBObject(layerTableRecord, true);
}
else
{
layerTableRecord = transaction.GetObject(layerTable[aLayer],OpenMode.ForWrite) as LayerTableRecord;
}
layerTableRecord.IsFrozen = true;
BlockTable blockTable = transaction.GetObject(database.BlockTableId, OpenMode.ForRead) as BlockTable;
BlockTableRecord blockTableRecord = transaction.GetObject(blockTable[BlockTableRecord.ModelSpace],OpenMode.ForWrite) as BlockTableRecord;
Circle cir = new Circle();
cir.Center = new Point3d(200, 300, 400);
cir.Radius = 500;
cir.Layer = aLayer;
blockTableRecord.AppendEntity(cir);
transaction.AddNewlyCreatedDBObject(cir, true);
transaction.Commit();
}
}
[CommandMethod("SetLayerColor")] //指定图层颜色
public void SetLayerColor()
{
Document doc = Application.DocumentManager.MdiActiveDocument;
Database database = doc.Database;
using (Transaction trans=database.TransactionManager.StartTransaction())
{
LayerTable layerTable = trans.GetObject(database.LayerTableId, OpenMode.ForWrite) as LayerTable;
string[] sLayerNames = new string[3];
sLayerNames[0] = "ACIRed";
sLayerNames[1] = "TrueBlue";
sLayerNames[2] = "ColorBookYellow";
Color[] acColors = new Color[3];
acColors[0] = Color.FromColorIndex(ColorMethod.ByAci,1);
acColors[1] = Color.FromRgb(23,54,232);
acColors[2] = Color.FromNames("PANTONE Yellow 0131 C","PANTONE(R) pastel coated");
int nCnt = 0;
foreach (string sLayerName in sLayerNames)
{
LayerTableRecord layerTableRecord;
if (layerTable.Has(sLayerName) == false)
{
layerTableRecord = new LayerTableRecord();
layerTableRecord.Name = sLayerName;
if (layerTable.IsWriteEnabled == false) layerTable.UpgradeOpen();
layerTable.Add(layerTableRecord);
trans.AddNewlyCreatedDBObject(layerTableRecord, true);
}
else
{
layerTableRecord = trans.GetObject(layerTable[sLayerName], OpenMode.ForWrite) as LayerTableRecord;
}
layerTableRecord.Color = acColors[nCnt];
nCnt++;
}
trans.Commit();
}
}
[CommandMethod("SetLayerLineType")]
public void SetLayerLineType() //设置图层线型
{
Document document = Application.DocumentManager.MdiActiveDocument;
Database database = document.Database;
using (Transaction transaction = database.TransactionManager.StartTransaction())
{
LayerTable layerTable = transaction.GetObject(database.LayerTableId,OpenMode.ForRead) as LayerTable;
string sLayerName = "ABC";
LayerTableRecord layerTableRecord;
if (layerTable.Has(sLayerName) == false)
{
layerTableRecord = new LayerTableRecord();
layerTableRecord.Name = sLayerName;
layerTable.UpgradeOpen();
layerTable.Add(layerTableRecord);
transaction.AddNewlyCreatedDBObject(layerTableRecord, true);
}
else
{
layerTableRecord = transaction.GetObject(layerTable[sLayerName], OpenMode.ForRead) as LayerTableRecord;
}
LinetypeTable linetypeTable = transaction.GetObject(database.LinetypeTableId, OpenMode.ForRead) as LinetypeTable;
if (linetypeTable.Has("Center") == true)
{
layerTableRecord.UpgradeOpen();
layerTableRecord.LinetypeObjectId = linetypeTable["Center"];
}
transaction.Commit();
}
}
[CommandMethod("EraseLayer")]
public void EraseLayer() //删除图层
{
Document document = Application.DocumentManager.MdiActiveDocument;
Database database = document.Database;
using (Transaction transaction=database.TransactionManager.StartTransaction())
{
LayerTable layerTable = transaction.GetObject(database.LayerTableId, OpenMode.ForRead) as LayerTable;
string sLayerName = "test1";
if (layerTable.Has(sLayerName) == true)
{
ObjectIdCollection objectIdCollection = new ObjectIdCollection();
objectIdCollection.Add(layerTable[sLayerName]);
//database.Purge(objectIdCollection);
if (objectIdCollection.Count>0)
{
LayerTableRecord layerTableRecord = transaction.GetObject(objectIdCollection[0], OpenMode.ForWrite) as LayerTableRecord;
try
{
layerTableRecord.Erase(true);
transaction.Commit();
}
catch(GrxCAD.Runtime.Exception ex)
{
Application.ShowAlertDialog("Error:\n" + ex.Message);
}
}
}
}
}
CAD.NET二次开发 新建图层 删除图层 指定图层颜色以及线形等的更多相关文章
- Qt+QGis二次开发:加载栅格图层和矢量图层
一.加载栅格图像 加载栅格图像的详细步骤在下面代码里: //添加栅格数据按钮槽函数 void MainWindow::addRasterlayers() { //步骤1:打开文件选择对话框 QStri ...
- NX二次开发-将对象移动到图层UF_OBJ_set_layer
#include <uf.h> #include <uf_obj.h> #include <uf_modl.h> #include <uf_layer.h&g ...
- 【NX二次开发】Block UI 指定矢量
属性说明 属性 类型 描述 常规 BlockID String 控件ID Enable Logical 是否可操作 Group ...
- Civil 3D 二次开发 新建CLR项目出现错误C2143
新建CLR项目出现错误C2143 按照Objectarx Training创建.net混合项目,编译时出现一下错误: 原因不明: 解决方法: 在Stdafx.h文件中添加: #define WIN32 ...
- Qt+QGIS二次开发:向shp矢量图层中添加新的字段
添加一个新的字段到shp文件中,并且从Excel里导入数据到该字段.原shp文件里的字段ID应该与Excel里的字段ID一一对应才能正确的导入.下图分别是shp的字段和Excel的字段 将class字 ...
- NX二次开发-UFUN编辑添加哪些图层UF_LAYER_edit_category_layer
1 NX11+VS2013 2 3 #include <uf.h> 4 #include <uf_layer.h> 5 6 7 UF_initialize(); 8 9 //创 ...
- NX二次开发-UFUN获取工程图视图边界线颜色UF_DRAW_ask_border_color
#include <uf.h> #include <uf_draw.h> #include <uf_ui.h> UF_initialize(); ; UF_DRAW ...
- 【NX二次开发】Block UI 指定轴
属性说明 属性 类型 描述 常规 BlockID String 控件ID Enable Logical 是否可操作 Group ...
- 【NX二次开发】Block UI 指定平面
属性说明 属性 类型 描述 常规 BlockID String 控件ID Enable Logical 是否可操作 Group ...
随机推荐
- appium+python 清空文本框EditText的值
清空EditText的自动化脚本编写流程: 前提条件:进入到要删除文本框的页面 1.查找到要删除的文本框,可通过id.name等属性进行查找 2.点击 3.通过get_attribute(" ...
- nginx安装部署(支持https)
1 安装环境准备 1.1 准备环境清单 以下是基本环境清单列表: 软件名称 版本号 说明信息 Linux CentOS 6.7 部署机器只需为Linux系统即可,无严格要求 1.2 ...
- java一个大接口拆用多线程方式拆分成多个小接口
问题引入 目的:我们的接口A 分别调用了a1 a2 a3 三个接口,最终返回值是 a1的返回值+a2的返回值+a3的返回值 如果同步执行 a1 a2 a3 然后结果相加 很慢 . 如果异步执行 无法 ...
- 『开源』扩展 JS 的 Date 处理函数
背景: JS 有自己的 时间类型 Date —— 但是,在某些情况下 这个对象似乎 不太好用. 本文 基于 JQuery 扩展了一些 JS日期函数,包括: > 字符串 转 Date 对象 万 ...
- Sqlserver事务隔离级别详解
sqlserver存储方式 页 sqlserver是以页的形式存储数据,每个数据页的大小为8KB,sqlserver会把空间分为多个页,sqlserver与数据交互单位最小的io操作就是页级 ...
- C语言超级搞笑的代码,冷笑话我们程序员也会讲的啊!
百年修得足下点击本文 欢迎来到"C语言基础"专题,今天我们放松一天,不学习知识,来看下大千世界的千奇百怪的C语言代码,你见过那些? 1.关于随机数这回事 这个随机数有点意思哦. 2 ...
- 使用 HttpRequester 更方便的发起 HTTP 请求
使用 HttpRequester 更方便的发起 HTTP 请求 Intro 一直感觉 .net 里面(这里主要说的是 .net framework 下)发送 HTTP 请求的方式用着不是特别好用,而且 ...
- 管道及I/O重定向
管道及IO 重定向 > < >> <<计算机组成: 运算器,控制器:CPU 存储器:RAM 输入/输出设备 I/O 程序: 指令和数据 控制器:指令 运算器: 存储 ...
- NSTimer循环引用的几种解决方案
前言 在iOS中,NSTimer的使用是非常频繁的,但是NSTimer在使用中需要注意,避免循环引用的问题.之前经常这样写: - (void)setupTimer { self.timer = [NS ...
- 浅析 jQuery 内部架构设计
jQuery 对于大家而言并不陌生,因此关于它是什么以及它的作用,在这里我就不多言了,而本篇文章的目的是想通过对源码简单的分析来讨论 jQuery 的内部架构设计,以及 jQuery 是如何利用Jav ...