你还没有发布完整的代码,所以很难确定。
有什么特别的原因不使用ReadDwgFile()方法将DXF作为边数据库打开,而不是在编辑器中打开?
快速示例:
- using Autodesk.AutoCAD.ApplicationServices;
- using Autodesk.AutoCAD.DatabaseServices;
- using Autodesk.AutoCAD.EditorInput;
- using System.IO;
- namespace FOO
- {
- public class BAR
- {
- void BAZ(string filePath)
- {
- if (!File.Exists(filePath))
- return;
- Document acDoc = Application.DocumentManager.MdiActiveDocument;
- Editor ed = acDoc.Editor;
- using (Database db = new Database(false, true))
- {
- try
- {
- db.ReadDwgFile(filePath, System.IO.FileShare.Read, false, "");
- }
- catch (System.Exception)
- {
- ed.WriteMessage(
- "\nUnable to read drawing file."
- );
- return;
- }
- using (Transaction tr = db.TransactionManager.StartOpenCloseTransaction())
- {
- BlockTable bt = (BlockTable)tr.GetObject(db.BlockTableId, OpenMode.ForRead);
- BlockTableRecord btr =
- (BlockTableRecord)tr.GetObject(bt[blockTableRecord.ModelSpace], OpenMode.ForRead);
- foreach (ObjectId id in btr)
- {
- [color="red"]//<-- do something useful here[/color]
- }
- }
- }
- }
- }
- }
谢谢你的帮助!! |