基于浩辰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二次开发 新建图层 删除图层 指定图层颜色以及线形等的更多相关文章

  1. Qt+QGis二次开发:加载栅格图层和矢量图层

    一.加载栅格图像 加载栅格图像的详细步骤在下面代码里: //添加栅格数据按钮槽函数 void MainWindow::addRasterlayers() { //步骤1:打开文件选择对话框 QStri ...

  2. NX二次开发-将对象移动到图层UF_OBJ_set_layer

    #include <uf.h> #include <uf_obj.h> #include <uf_modl.h> #include <uf_layer.h&g ...

  3. 【NX二次开发】Block UI 指定矢量

    属性说明 属性   类型   描述   常规           BlockID    String    控件ID    Enable    Logical    是否可操作    Group    ...

  4. Civil 3D 二次开发 新建CLR项目出现错误C2143

    新建CLR项目出现错误C2143 按照Objectarx Training创建.net混合项目,编译时出现一下错误: 原因不明: 解决方法: 在Stdafx.h文件中添加: #define WIN32 ...

  5. Qt+QGIS二次开发:向shp矢量图层中添加新的字段

    添加一个新的字段到shp文件中,并且从Excel里导入数据到该字段.原shp文件里的字段ID应该与Excel里的字段ID一一对应才能正确的导入.下图分别是shp的字段和Excel的字段 将class字 ...

  6. 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 //创 ...

  7. NX二次开发-UFUN获取工程图视图边界线颜色UF_DRAW_ask_border_color

    #include <uf.h> #include <uf_draw.h> #include <uf_ui.h> UF_initialize(); ; UF_DRAW ...

  8. 【NX二次开发】Block UI 指定轴

    属性说明 属性   类型   描述   常规           BlockID    String    控件ID    Enable    Logical    是否可操作    Group    ...

  9. 【NX二次开发】Block UI 指定平面

    属性说明 属性   类型   描述   常规           BlockID    String    控件ID    Enable    Logical    是否可操作    Group    ...

随机推荐

  1. Resnet论文翻译

    摘要 越深层次的神经网络越难以训练.我们提供了一个残差学习框架,以减轻对网络的训练,这些网络的深度比以前的要大得多.我们明确地将这些层重新规划为通过参考输入层x,学习残差函数,来代替没有参考的学习函数 ...

  2. 【BAT面试题系列】面试官:你了解乐观锁和悲观锁吗?

    前言 乐观锁和悲观锁问题,是出现频率比较高的面试题.本文将由浅入深,逐步介绍它们的基本概念.实现方式(含实例).适用场景,以及可能遇到的面试官追问,希望能够帮助你打动面试官. 目录 一.基本概念 二. ...

  3. 【ODI】| 数据ETL:从零开始使用Oracle ODI完成数据集成(二)

    前一节已经完成了Oracle数据库和ODI的安装,并已经为ODI在Oracle数据库中创建了两个用户,分别用于存放主资料库数据和工作资料库数据,在ODI中完成主资料库和工作资料库的创建,也分别为其创建 ...

  4. Mybatis之旅第六篇-关联查询

    一.引言 通过动态SQL我们可以进行复杂SQL的编写,但之前的例子都是单表查询,在实际开发中,当然不可能都是单表,很多时候我们需要进行关联多表查询(有些公司为了性能还是尽量的使用单表查询),表与表之间 ...

  5. HashMap?面试?我是谁?我在哪

    现在是晚上11点了,学校屠猪馆的自习室因为太晚要关闭了,勤奋且疲惫的小鲁班也从屠猪馆出来了,正准备回宿舍洗洗睡,由于自习室位置比较偏僻所以是接收不到手机网络信号的,因此小鲁班从兜里掏出手机的时候,信息 ...

  6. SpringBoot进阶教程(二十七)整合Redis之分布式锁

    在之前的一篇文章(<Java分布式锁,搞懂分布式锁实现看这篇文章就对了>),已经介绍过几种java分布式锁,今天来个Redis分布式锁的demo.redis 现在已经成为系统缓存的必备组件 ...

  7. java并发编程(2) --Synchronized与Volatile区别

    Synchronized 在多线程并发中synchronized一直是元老级别的角色.利用synchronized来实现同步具体有一下三种表现形式: 对于普通的同步方法,锁是当前实例对象. 对于静态同 ...

  8. 使用LXD搭建Web网站

    欢迎大家前往腾讯云+社区,获取更多腾讯海量技术实践干货哦~ 本文由独木桥先生 发表于云+社区专栏 介绍 Linux的容器是Linux的一组进程,通过使用Linux内核功能与系统隔离.它是一个类似于虚拟 ...

  9. DML(数据操纵语言)

    1.概念(C) 数据操纵语言 DML (Data Manipulation Langua)是SQL语言的一个分类,用于对表的内容或者说数据进行增.删.改.查等操作. 通过以下几个关键字实现: SELE ...

  10. iftop命令使用范例

    iftop 介绍 iftop是一款实时流量监控工具,监控TCP/IP连接等,缺点就是无报表功能.必须以root身份才能运行. 实例 默认是监控第一块网卡的流量 iftop 监控eth1 iftop - ...