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

Teigha(ODA<Open Design Alliance>_开放设计联盟)——cad c# 二次开发

 需将dll库文件与exe文件放同一路径下,运行exe即可执行。

 

using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.IO;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using System.Windows.Forms;
using Teigha.DatabaseServices;
using Teigha.Geometry;
using Teigha.Runtime;

namespace WindowsFormsApp1
{
    public partial class Form1: Form
    {
        public Form1()
        {
            InitializeComponent();
        }

        private void button1_Click(object sender, EventArgs e)
        {
            using (Services svc = new Services())
            {
                string desktopPath = System.Environment.GetFolderPath(System.Environment.SpecialFolder.Desktop);
                string fname = Path.Combine(desktopPath, "teigha创建的文件.dwg");
                Database db = new Database();
                using (var tr = db.TransactionManager.StartTransaction())
                {
                    BlockTableRecord btr = (BlockTableRecord)tr.GetObject(db.CurrentSpaceId, OpenMode.ForWrite);
                    for (int i = 0; i < 200; i++)
                    {
                        Point3d pt1 = new Point3d(i, i + 200, 0);
                        string str = "aaa" + i.ToString();
                        DBText txt = new DBText();
                        txt.Position = pt1;
                        txt.TextString = str;

                        btr.AppendEntity(txt);
                        tr.AddNewlyCreatedDBObject(txt, true);

                    }
                    tr.Commit();
                    db.SaveAs(fname, DwgVersion.AC1027);
                    db.Dispose();
                }
            }
        }

        private void button2_Click(object sender, EventArgs e)
        {
            using (Services svc = new Services())
            {
                string desktopPath = Environment.GetFolderPath(Environment.SpecialFolder.Desktop);
                string fname = Path.Combine(desktopPath, "teigha创建的文件.dwg");
                Database db = new Database(false, false);
                db.ReadDwgFile(fname, System.IO.FileShare.Read, false, null);
                using (var tr = db.TransactionManager.StartTransaction())
                {
                    BlockTableRecord btr = (BlockTableRecord)tr.GetObject(db.CurrentSpaceId, OpenMode.ForWrite);
                    Circle cir = new Circle();
                    for (global::System.Int32 i = 0; i < 20; i++)
                    {
                        Point3d pt1 = new Point3d(i, i * 2, 0);
                        double rad = 100;

                        cir.Center = pt1;
                        cir.Radius = rad;
                        cir.ColorIndex = i;


                    }
                    btr.AppendEntity(cir);
                    tr.AddNewlyCreatedDBObject(cir, true);
                    tr.Commit();
                    db.Save();
                    db.Dispose();
                }
            }
        }

        private void button3_Click(object sender, EventArgs e)
        {
            using (Services ser = new Services())
            {
                string desktopPath = Environment.GetFolderPath(Environment.SpecialFolder.Desktop);
                string fname = Path.Combine(desktopPath, "teigha创建的文件.dwg");
                Database db = new Database(false, false);
                db.ReadDwgFile(fname, System.IO.FileShare.Read, false, null);
                using (var trans = db.TransactionManager.StartTransaction())
                {
                    BlockTableRecord btrec = (BlockTableRecord)trans.GetObject(db.CurrentSpaceId, OpenMode.ForWrite);
                    foreach (ObjectId objid in btrec)
                    {
                        Entity ent = trans.GetObject(objid, OpenMode.ForWrite) as Entity;
                        if (ent.GetType().Name == "DBText")
                        {
                            DBText txt = (DBText)ent;
                            if (txt.TextString == "aaa2")
                            {
                                txt.TextString = "teigha";
                            }
                        }
                    }
                    trans.Commit();
                }
                db.Save();
                db.Dispose();
            }
        }
    }
}

http://www.dtcms.com/a/35310.html

相关文章:

  • 英式英语与美式英语的单词拼写差异
  • 第4章 4.3 EF Core 的实体类配置 Data Annatation Fluent API
  • 死锁是什么
  • git 小乌龟安装包及中文包
  • 计网学习————(二)
  • 第十三:路由两个注意点:
  • web组态可视化编辑器
  • C语言函数学习笔记
  • 【js面试】JavaScript中执行栈和执行上下文是什么?
  • GraphRAG如何使用ollama提供的llm model 和Embedding model服务构建本地知识库
  • 【C++11】 并发⽀持库
  • next.js-学习2
  • Python常用的15个标准模块
  • 如何选择适合项目的自动化测试工具?
  • Linux项目自动化构建工具-make/Makefile (linux第六课)
  • DeepSeek 助力 Vue 开发:打造丝滑的文本输入框(Text Input)
  • vue框架后遗症∶被遗忘的dom操作
  • DeepSeek R1模型提示语技巧:如何高效引导AI生成优质内容
  • 具有快慢思考的语言调节机器人操作
  • VXLAN与园区网络虚拟化
  • (六)趣学设计模式 之 代理模式!
  • 分割数组的最大差值
  • 无人机实战系列(番外一)本地图像+Apple ML Depth Pro
  • 算法-数据结构-图的构建(邻接矩阵表示)
  • 图数据库Neo4j面试内容整理-约束(Constraint)
  • C++面向对象编程技术研究
  • 6.1 - UART串口数据收发环回实验
  • 代码随想录第三十八天| 322. 零钱兑换 279.完全平方数 139.单词拆分 动态规划:关于多重背包,你该了解这些!
  • 布隆过滤器:一种简单而高效的集合查询方法
  • git中,如何查看具体单个文件的log