miki969696

CAD开发 获取当前文档

Document doc = Application.DocumentManager.MdiActiveDocument;//获取当前文档
using Application = Autodesk.AutoCAD.ApplicationServices.Application;   //获取 application
//获取当前文档数据库
 Document doc = Application.DocumentManager.MdiActiveDocument;//获取当前文档
 Database db = doc.Database;//获取文档的数据库
//获取其他文档的数据库:DWG文档
string filePath = "D:\\HelloWorld\\LearnCAD\\测试.dwg";
using (Database database = new Database(false, true))
{
    database.ReadDwgFile(filePath, System.IO.FileShare.Read, false, null);//读取DWG文件
    database.CloseInput(true); //关闭文件
}
//获取其他文档的数据库  DXF文档
string filePath = "D:\\HelloWorld\\LearnCAD\\测试.dxf";
using (Database database = new Database(false, true))
{
    database.DxfIn(filePath, "");//读取DXF文件
    database.CloseInput(true);//关闭文件
}
//获取当前文档的编辑器
 Document doc = Application.DocumentManager.MdiActiveDocument;//获取当前文档
 Database db = doc.Database;//获取文档的数据库
 Editor ed=doc.Editor;//获取文档的编辑器
//打开文件夹里面的DWG文档
string filePath = "D:\\HelloWorld\\LearnCAD\\测试.dwg";
DocumentCollection docManager = Application.DocumentManager;
Document doc1 = docManager.Open(filePath);//默认方式打开
Document doc2 = docManager.Open(filePath,false);//是否以只读方式打开:false

posted on 2025-11-15 04:56  sswsswssw1996  阅读(0)  评论(0)    收藏  举报

导航