当前位置: 首页 > 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();
            }
        }
    }
}

相关文章:

  • 英式英语与美式英语的单词拼写差异
  • 第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与园区网络虚拟化
  • 花290多万维修保质期仅一年多?媒体四问凤阳鼓楼“瓦片脱落”
  • 特朗普与普京就俄乌问题通话
  • 招商基金总经理徐勇因任期届满离任,“老将”钟文岳回归接棒
  • 印军称中国向巴基斯坦提供防空系统协助,外交部:中方十分重视与印、巴两国关系
  • 广东茂名高州市山体滑坡已致3死1失联,搜救仍在继续
  • 李公明 | 一周画记:德里达哲学还是接地气的