Teigha简单实例
本帖最后由 雪山飞狐_lzh 于 2016-2-2 15:19 编辑Teigha,雪山飞狐_lzh 版主有过介绍,并有实例程序,但我觉得那太复杂了,不适合新手,所以发一个基于Teigha4.0,C#,.NET4.0的最基本应用的例子。附件为源码。 using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Windows.Forms;
using System.IO;
using Teigha.DatabaseServices;
using Teigha.Runtime;
using Teigha.Geometry;
using Teigha.GraphicsInterface;
using Teigha.GraphicsSystem;
namespace RepText
{
public partial class Form1 : Form
{
public Form1()
{
InitializeComponent();
}
private void button1_Click(object sender, EventArgs e)
{
using (Services ser = new Services())
{
string fname = "D:\\aaa.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 == "aaa")
{
txt.TextString = "bbb";
}
}
}
trans.Commit();
}
db.Save();
db.Dispose();
}
}
private void button2_Click(object sender, EventArgs e)
{
using (Services svc = new Services())
{
string fname = "D:\\aaa.dwg";
Database db = new Database();
using (var tr = db.TransactionManager.StartTransaction())
{
Point3d pt1 = new Point3d(0, 0, 0);
string str = "aaa";
DBText txt = new DBText();
txt.Position = pt1;
txt.TextString= str;
BlockTableRecord btr = (BlockTableRecord)tr.GetObject(db.CurrentSpaceId, OpenMode.ForWrite);
btr.AppendEntity(txt);
tr.AddNewlyCreatedDBObject(txt, true);
tr.Commit();
db.SaveAs(fname,DwgVersion.AC1800);
db.Dispose();
}
}
}
private void button3_Click(object sender, EventArgs e)
{
using (Services svc = new Services())
{
string fname = "D:\\aaa.dwg";
Database db = new Database(false,false);
db.ReadDwgFile(fname, System.IO.FileShare.Read,false , null);
using (var tr = db.TransactionManager.StartTransaction())
{
Point3d pt1 = new Point3d(0, 0, 0);
double rad = 1000;
Circle cir = new Circle();
cir.Center = pt1;
cir.Radius = rad;
BlockTableRecord btr = (BlockTableRecord)tr.GetObject(db.CurrentSpaceId, OpenMode.ForWrite);
btr.AppendEntity(cir);
tr.AddNewlyCreatedDBObject(cir, true);
tr.Commit();
db.Save();
db.Dispose();
}
}
}
}
}
例子包括新建DWG文件并写入文字,后台打开DWG文件画圆,后台文字替换 不好意思,发成要钱的了,重发·。 很好~... 好像飞诗说官方的例子有一个能实现选择图形的 用鼠标不知道在哪里-.- 谢谢……………… 请问下,是不是用这个,不受版本限制? 用这个直接就脱离CAD操作DWG文件 本帖最后由 paciguard 于 2016-1-26 10:53 编辑
楼主好,请问使用Teigha 4.0,都需要应用哪些库文件,除了TD_Mgd_4.00_10.dll。VS2012。
多谢!!! 谢谢楼主!看了你的程序,我的是用VB编的,目标平台X86,Teigha的2个库文件都引用了,但运行提示:创建窗体出错,未能加载文件或"TD_Mgd_4.00_10.dll"或它的某一个依赖项。
麻烦帮忙看看。多谢!
页:
[1]
2