当前位置: 首页 > news >正文

c# cad 二次开发 类库 CAD表格的操作,给CAD添加一个表格

c# cad 二次开发 类库 CAD表格的操作,给CAD添加一个表格
using Autodesk.AutoCAD.ApplicationServices;
using Autodesk.AutoCAD.Colors;
using Autodesk.AutoCAD.DatabaseServices;
using Autodesk.AutoCAD.EditorInput;
using Autodesk.AutoCAD.Geometry;
using Autodesk.AutoCAD.Runtime;
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;

namespace _15表格操作
{
public class Class1
{
public struct BlockData
{
public string blockName;
public string layerName;
public string X;
public string Y;
public string Z;
public string ZS;
public string XS;
}

[CommandMethod(“TableDemo”)]
public void TableDemo()
{
Database db = HostApplicationServices.WorkingDatabase;
Table table = new Table();
table.SetSize(10, 5);
table.SetRowHeight(10);
table.SetColumnWidth(50);
table.Columns[0].Width = 20;
table.Position = new Point3d(100, 100, 0);
//table.SetTextString(0, 0, “材料统计表”);早前版本的设置方法
table.Cells[0, 0].TextString = “材料统计表”;
table.Cells[0, 0].TextHeight = 6;
Color color = Color.FromColorIndex(ColorMethod.ByAci,3);
table.Cells[0, 0].BackgroundColor = color;
color = Color.FromColorIndex(ColorMethod.ByAci, 1);
table.Cells[0, 0].ContentColor = color;
using (Transaction trans = db.TransactionManager.StartTransaction())
{
BlockTable bt = (BlockTable)trans.GetObject(db.BlockTableId, OpenMode.ForRead);
BlockTableRecord btr = (BlockTableRecord)trans.GetObject(bt[BlockTableRecord.ModelSpace], OpenMode.ForWrite);
btr.AppendEntity(table);
trans.AddNewlyCreatedDBObject(table, true);
trans.Commit();
}
}

[CommandMethod(“DataToTableDemo”)]
public void DataToTableDemo()
{
Database db = HostApplicationServices.WorkingDatabase;
Editor ed = Application.DocumentManager.MdiActiveDocument.Editor;
TypedValue[] values = new TypedValue[]
{
new TypedValue((int)DxfCode.Start,“INSERT”),
new TypedValue((int)DxfCode.LayerName,“ssd”)
};
SelectionFilter filter = new SelectionFilter(values);
PromptSelectionResult psr = ed.GetSelection(filter);
if (psr.Status == PromptStatus.OK)
{
ObjectId[] ids = psr.Value.GetObjectIds();
PromptPointResult ppr = ed.GetPoint(“选择表格的插入点:”);
if (ppr.Status == PromptStatus.OK)
{
Point3d point = ppr.Value;
BlockData[] data = this.GetBlockRefData(db, ids);
this.SetDataToTable(db, data, point);
}
}
}
///
/// 将数据以表格的形式插入图形
///
///
///
///
private void SetDataToTable(Database db, BlockData[] data, Point3d position)
{
using (Transaction trans = db.TransactionManager.StartTransaction())
{
//Table table = new Table();
TableExt table = new TableExt(data.Length, 7,position,data,“块数据统计表”);
BlockTable bt = (BlockTable)trans.GetObject(db.BlockTableId, OpenMode.ForRead);
BlockTableRecord btr = (BlockTableRecord)trans.GetObject(bt[BlockTableRecord.ModelSpace], OpenMode.ForWrite);
btr.AppendEntity(table);
trans.AddNewlyCreatedDBObject(table, true);
trans.Commit();
}
}
///
/// 获取块参照的信息
///
///
///
///
private BlockData[] GetBlockRefData(Database db, ObjectId[] ids)
{
BlockData[] data = new BlockData[ids.Length];
using (Transaction trasn = db.TransactionManager.StartTransaction())
{
for (int i = 0; i < ids.Length; i++)
{
// 块名 图层 X Y Z ZS XS
BlockReference br = (BlockReference)ids[i].GetObject(OpenMode.ForRead);
data[i].blockName = br.Name;
data[i].layerName = br.Layer;
data[i].X = br.Position.X.ToString();
data[i].Y = br.Position.Y.ToString();
data[i].Z = br.Position.Z.ToString();
foreach (ObjectId item in br.AttributeCollection)
{
AttributeReference attRef = (AttributeReference)item.GetObject(OpenMode.ForRead);
if (attRef.Tag.ToString() == “ZS”)
{
data[i].ZS = attRef.TextString;
}
else if (attRef.Tag.ToString() == “XS”)
{
data[i].XS = attRef.TextString;
}
}
}
}
return data;
}
}
}

http://www.lryc.cn/news/91508.html

相关文章:

  • 单点登录的两种实现方式,分别有啥优缺点?
  • opencv_c++学习(二十七)
  • 探查chatGPT插件:Outschool,resume,webhooks
  • 【学习笔记】Unity基础(七)【uGUI基础、利用render Texture实现小地图功能】
  • yolov5配置错误记录
  • 全平台数据 (数据库) 管理工具 DataCap 1.10.0 发布
  • 使用Mybatis接口开发
  • 数据采集技术的实现原理有哪些?
  • 2023年数学建模随机森林:基于多个决策树的集成学习方法
  • OpenAI发布最新研究让大模型数学推理直接达到SOTA
  • 快速检测 GlassFish 任意文件读取漏洞的 Python 脚本
  • Docker镜像更新通知器DIUN
  • 插件框架PF4J-从理论到实践
  • 怎么将pdf文件免费转为扫描件
  • vue+nodejs校园二手物品交易市场网站_xa1i4
  • Barra模型因子的构建及应用系列六之Book-to-Price因子
  • 【c语言习题】使用链表解决约瑟夫问题
  • JVM之类的初始化与类加载机制
  • 面试专题:java 多线程(1)----synchronized关键字相关问答
  • VMware SD-WAN 5.2 发布 - 软件定义的 WAN
  • Oracle+11g+RAC+PSU_EAM(2)
  • 智能出行 驱动未来|2023 开放原子全球开源峰会 CARSMOS 开源智能出行生态年会即将启幕
  • Linux:centos:周期性计划任务管理《crontab》
  • 克拉默法则证明(Cramer‘s Rule)
  • 【接口防刷】处理方案
  • 安装Linux-SUSE操作系统
  • 二、机器人的结构设计
  • UITableView学习笔记
  • Nginx反向代理与负载均衡
  • Delaunay三角剖分学习笔记