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

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.kler.cn/a/560621.html

相关文章:

  • 原生稀疏注意力NSA 替换transformer 注意力进行文本生成训练
  • 【开源免费】基于SpringBoot+Vue.JS物流管理系统(JAVA毕业设计)
  • 普通人使用生成式语言模型的几个阶段
  • javaweb-vue3基础
  • R Excel 文件:高效数据处理的利器
  • 在CentOS 7下部署NFS的详细教程
  • 一些时间方法
  • 如何保证bug在改完之后不会引起新bug
  • 如何通过阿里云CDN优化网站访问与下载速度?
  • 数据库-事务的ACID
  • Linux 系统内存不足导致服务崩溃的排查方法
  • TCP重传机制
  • 使用 Three.js 转换 GLSL 粒子效果着色器
  • 【C++设计模式】观察者模式(1/2):从基础到优化实现
  • Mesh自组网技术及应用
  • 网络运维学习笔记(DeepSeek优化版)002网工初级(HCIA-Datacom与CCNA-EI)子网划分与协议解析
  • 七.智慧城市数据治理平台架构
  • 【LeetCode 热题100】48. 旋转图像以及旋转任意角度的算法思路及python代码
  • LabVIEW Browser.vi 库说明
  • H5--开发适配