- 积分
- 4400
- 明经币
- 个
- 注册时间
- 2015-1-16
- 在线时间
- 小时
- 威望
-
- 金钱
- 个
- 贡献
-
- 激情
-
|
发表于 2021-11-19 17:01:01
|
显示全部楼层
本帖最后由 qq1254582201 于 2021-11-19 17:02 编辑
https://adndevblog.typepad.com/a ... ng-readdwgfile.html
这应该是你想要的答案!!- eNoInputFiler exception when using ReadDwgFile
- By Adam Nagy
- When I run the following code I get an eNoInputFiler exception when calling ReadDwgFile. What could be the problem?
- using System;
- using System.IO;
- using Autodesk.AutoCAD.DatabaseServices;
- using Autodesk.AutoCAD.Runtime;
- using acApp = Autodesk.AutoCAD.ApplicationServices.Application;
- using Autodesk.AutoCAD.ApplicationServices;
- [assembly: CommandClass(typeof(MyAddIn.Commands))]
- namespace MyAddIn
- {
- public class Commands
- {
- [CommandMethod("MyCmd", CommandFlags.Session)]
- public static void MyCmd()
- {
- Document doc = acApp.DocumentManager.MdiActiveDocument;
- using (Database db = new Database(false, false))
- {
- db.ReadDwgFile(
- @"C:\testdwg.dwg", FileShare.Read, false, null);
- // do something with it
- }
- }
- }
- }
- Solution
- The second parameter of the Database constructor (noDocument) controls if the Database should be associated with the current document or not.
- Probably the main reason to decide to associate the Database with a document would be to participate in Undo: see ObjectARX Reference > Document-Independent Databases
- In this case you would need to do document locking (and since you are in Session context because of CommandFlags.Session, you would need to do it yourself, explicitly, using Document.LockDocument())
- However if you do not associate the Database with the current document, then no locking is needed.
- So the solution is to either lock the Document when you want to associate your Database with it (noDocument = false):
- [CommandMethod("MyCmd", CommandFlags.Session)]
- public static void MyCmd()
- {
- Document doc = acApp.DocumentManager.MdiActiveDocument;
- using (doc.LockDocument())
- {
- using (Database db = new Database(false, false))
- {
- db.ReadDwgFile(
- @"C:\testdwg.dwg", FileShare.Read, false, null);
- // do something with it
- }
- }
- }
- ... or don’t associate the Database with the current document (noDocument = true, much more common)
- [CommandMethod("MyCmd", CommandFlags.Session)]
- public static void MyCmd()
- {
- using (Database db = new Database(false, true))
- {
- db.ReadDwgFile(
- @"C:\testdwg.dwg", FileShare.Read, false, null);
- // do something with it
- }
- }
|
|