关于创建Database的问题
创建Database时可以传入两个参数new Database(buildDefaultDrawing,noDocument)其中第二个参数表示是否与当前文档产生关联(帮助的原文 specifying whether or not to associate this database to the current document)
如果没有关联,还好理解,就是无任何关系。那么有关联时,新建的Database对象与当前文档之间有什么关系呢?能体现在什么地方?
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;
namespace MyAddIn
{
public class Commands
{
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):
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)
public static void MyCmd()
{
using (Database db = new Database(false, true))
{
db.ReadDwgFile(
@"C:\testdwg.dwg", FileShare.Read, false, null);
// do something with it
}
}
谢谢,学习了!!
页:
[1]