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 ...
随机推荐
- Java Applet 与Servlet之间的通信
1 Applet对Servlet的访问及参数传递的实现 2.1.1创建URL对象 在JAVA程序中,可以利用如下的形式创建URL对象 URL servletURL = new URL( "h ...
- MIP技术进展月报第3期:MIP小姐姐听说,你想改改MIP官网?
一. 官网文档全部开源 MIP 是一项永久的开源的项目,提供持续优化的解决方案,当然官网也不能例外.从现在开始,任何人都可以在 MIP 官网贡献文档啦! GitHub 上,我们已经上传了 <官网 ...
- Android编译自己的程序到/system/bin
背景 有时候我们想创建一个程序,放在系统中,供其他APP执行.我们知道,在生成system.img的时候,编译系统会将out/target/product/[product]/system/bin目录 ...
- C#相等性 - 三个方法和一个接口
简介 C#(.NET)的object类里面有三个关于判断相等性的方法: public virtual bool Equals(object obj) public static bool Equals ...
- 抽象工厂模式--java代码实现
抽象工厂模式 抽象工厂模式,对方法工厂模式进行抽象.世界各地都有自己的水果园,我们将这些水果园抽象为一个水果园接口,在中国.英国和美国都有水果园,种植不同的水果,比如苹果.香蕉和梨等.这里将苹果进行抽 ...
- java游戏开发杂谈 - 实现游戏主菜单
经常玩游戏的同学,大家都知道,游戏都会有个主菜单,里面有多个菜单选项:开始游戏.游戏设置.关于游戏.退出游戏等等,这个菜单是怎么实现的呢. 有一定桌面软件开发基础的同学可能会想到,用JButton组件 ...
- JPA中自定义的插入、更新、删除方法为什么要添加@Modifying注解和@Transactional注解?
前几天,有个同事在使用JPA的自定义SQL方法时,程序一直报异常,捣鼓了半天也没能解决,咨询我的时候,我看了一眼他的程序,差不多是这个样子的: @Repository public interface ...
- 『发呆』.Net 2.0 ~ .Net 4.0 所实现了那些底层
随着时间的推移,程序越写越大,代码越写越少. 今天突然发呆,就想比较全面的汇总一下 .Net 2.0 和 .Net 4.0 都实现的功能. .Net 2.0 的大部分常见程序集 (已经过滤掉了一部分和 ...
- Redis调用的流程(新手使用)
就用查省市为例,别人还没查就把所有都弄好,很浪费资源和时间,redis是为了存储常用的查询操作的[结果],以此来减少直接查询数据库的次数,以下内容仅供参考,请勿照抄.(如有说得不好之处,请指点.) 言 ...
- C# 填充Excel图表、图例背景色
填充背景色,一般可以选择多种不同样式来填充背景,包括填充为纯色背景.渐变背景.图片背景或者纹理背景等.下面的内容将分别介绍通过C#来设置Excel中图表背景色.以及图表中的图例背景色的方法. 使用工具 ...