一、安装下载需要的环境。

VS2012、Teigha.NET3.03_9的demo

二、新建C# 项目,选择Framework2.0作为目标框架。

添加引用“TD_Mgd_3.03_9.dll"

三、开始写代码,首先初始化Teigha.NET

using (Services svcs = new Services()){

}


Teigha.NET的命名空间主要有以下这些:


  • Teigha.Colors Namespace— Corresponds to OdCm unmanaged classes. Contains classes for working with colors.
  • Teigha.DatabaseServices Namespace— Corresponds to OdDb unmanaged classes. Contains database classes.
  • Teigha.Geometry Namespace— Corresponds to OdGe unmanaged classes. Used to carry out general 2D and 3D geometric operations.
  • Teigha.GraphicsInterface Namespace— Corresponds to OdGi unmanaged classes. Contains classes for entity vectorization.
  • Teigha.GraphicsSystem Namespace— Corresponds to OdGs unmanaged classes. Contains graphical system classes.
  • Teigha.Runtime Namespace— Contains system-level functionality classes, such as classes for runtime class registration and identification.

四、Database结构 使用Teigha.NET操作DWG基本配置_3d

五、示例:

using Teigha.Runtime;
using Teigha.DatabaseServices;
using Teigha.Geometry;

namespace BatchReplaceText
{
class Program
{
static void Main(string[] args)
{
using (Services svcs = new Services()) {
Database db=new Database();
Circle cirl = new Circle();
cirl.Center = new Point3d(100, 100, 0);
cirl.Radius = 14;
BlockTableRecord btr = (BlockTableRecord)db.CurrentSpaceId.Open(OpenMode.ForWrite);
btr.AppendEntity(cirl);
db.SaveAs("C:\\test.dwg", DwgVersion.Current);
}
}
}
}