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 ...
随机推荐
- input表单中嵌入百度地图
在做项目开发中,常常会用到定位的操作,比如在做一些资产房产等方面的业务的时候,需要知道资产的具体位置,并将位置信息保存下来,这个时候我们可以使用form表单嵌入百度地图的方式来实现这个功能,下面请看详 ...
- PCB泪滴设计
操作:选择[Tools]-->[Teardrops],快捷键T+E.打开[Teardrop Options]对话框进行设置.如下图所示: 对话框面板介绍 [General] 1.该区域的[Pad ...
- Map集合中,关于取值和遍历的相关操作
这是自己的关于map集合的相关操作的小研究,分享给大家. 主要代码内容包含以下: 1,map集合的遍历 2,根据key值获取value值 3,根据value值获取key值 4,返回最大value值对应 ...
- java常用的框架介绍
一.SpringMVC http://blog.csdn.net/evankaka/article/details/45501811 Spring Web MVC是一种基于Java的实现了Web MV ...
- 并发的核心:CAS 与synchronized, Java8是如何优化 CAS 的?
大家可能都听说说 Java 中的并发包,如果想要读懂 Java 中的并发包,其核心就是要先读懂 CAS 机制,因为 CAS 可以说是并发包的底层实现原理. 今天就带大家读懂 CAS 是如何保证操作的原 ...
- go语言调度器源代码情景分析之三:内存
本文是<go调度器源代码情景分析>系列 第一章 预备知识的第2小节. 内存是计算机系统的存储设备,其主要作用是协助CPU在执行程序时存储数据和指令. 内存由大量内存单元组成,内存单元大小为 ...
- C#爬虫使用代理刷csdn文章浏览量
昨天写了一篇关于“c#批量抓取免费代理并验证有效性”的文章,接着昨天的目标继续完成吧,最终实现的目的就是刷新csdn文章的浏览量(实际上很简单,之前博客园的文章也是可以使用代理ip来刷的,后来不行了) ...
- 由dubbo服务禁用system.gc而引起的思考
我一直都有一个疑问,丰巢业务服务的生产环境jvm参数设置是禁止system.gc的,也就是开启设置:-XX:+DisableExplicitGC,但是生产环境却从来没有出现过堆外内存溢出的情况.说明一 ...
- bash语法
国际惯例打印hello world echo "hello world" 该程序运行结果: hello world 1.变量: a=;b="hello wor ...
- Github排序(转载)
目录 1. 冒泡排序 2. 选择排序 3. 插入排序 4. 希尔排序 5. 归并排序 6. 快速排序 7. 堆排序 8. 计数排序 9. 桶排序 10. 基数排序 参考:https://mp.weix ...