- 积分
- 1643
- 明经币
- 个
- 注册时间
- 2008-11-29
- 在线时间
- 小时
- 威望
-
- 金钱
- 个
- 贡献
-
- 激情
-
|
楼主 |
发表于 2016-1-22 21:53:04
|
显示全部楼层
- 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();
- }
- }
- }
- }
- }
|
|