.Net文档。CloseAndDis公司汽车
这是在Map 3D 2013中工作的。。。基本上,我想做的是:
[列表=1]
[*]打开dxf文件
[*]将其数据库复制到新的dwg文件
[*]关闭dxf
我对代码进行了一点修改,试图使其与Map 2014兼容,但没有成功。
这是我现在的代码:
// Open dxf
DocumentDocument doc = AcadUtil.DocumentManager.Open(dxfFileName, false);
// Lock Document so nothing interferes
using (DocumentLock docLock = doc.LockDocument())
{
// Save drawing as DWG file
using (Transaction tr = doc.Database.TransactionManager.StartTransaction())
{
doc.Database.SaveAs(fileName + ".dwg", DwgVersion.Newest);
tr.Commit();
}
}
// Set document active so we can close it
if (Application.DocumentManager.MdiActiveDocument != doc)
{
Application.DocumentManager.MdiActiveDocument = doc;
}
// Dispose db
doc.Database.Dispose();
// Close document
doc.CloseAndDiscard();
代码在文档上引发错误。CloseAndDiscard();
检测到FatalExecutionEngineError。。。
我尝试了很多不同的事情,现在我不知道该怎么做才能让这一切奏效。
我读过关于系统变量FIBERWORLD。。。设置为1。
我做错了什么??
谢谢你的帮助。 我把你的线移到了。NET、ObjectARX和VBA论坛。
你还没有发布完整的代码,所以很难确定。
有什么特别的原因不使用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, OpenMode.ForRead);
foreach (ObjectId id in btr)
{
//<-- do something useful here
}
}
}
}
}
}
谢谢你的帮助!! 在调试环境外运行我的代码,只需在Map 3D 2014中导入我的dll即可!!!
调试中的某些内容一定会以某种方式损坏堆栈。。。
运行我的代码进一步揭示了我的另一个问题。我在配置文件中声明了FDO提供程序(OSGeo.SQLServerSpatial)版本。
Map 3D 2013使用3.7,Map 3D 2014使用3.8。
我甚至意识到你根本不需要声明FDO提供商的版本,它仍然有效!
谢谢你的帮助,非常感谢! 垂直(例如Civil 3D)就像洋葱。。。Civil 3D构建在Map 3D之上,Map 3D本身构建在AutoCAD之上。。。为了执行给定的任务,您只需要访问适当的“洋葱”层(在本例中是AutoCAD,而不是Map)。
如果您正在通过网络加载程序集(一个插件,而不是独立的应用程序),那么当您可以使用应用程序时,甚至不需要使用AcadUtil(COM对象,这也使您的代码与环境相关,即x86或x64)。本机的DocumentManager对象。NET API并编译到任何CPU。。。我忘记了哪个框架实现了动态(4.0?),但这是另一种排除环境依赖性(早期/晚期绑定)的方法,同时利用COM(如果这是您真正想要的途径)。
此外,您可能会发现自动加载机制很有用,这里有一个最新的线程可能会有所帮助。
干杯 Verticals (for example, Civil 3D) are like an onion... Civil 3D is built on top of Map 3D, which is itself built on top of AutoCAD... You need only access the appropriate 'onion' layer (in this instance AutoCAD, not Map) in order to perform a given task.
If you're NETLOADing your assembly (a plug-in, not stand alone app), then there's no need to even use AcadUtil (COM Object, which also makes your code environment dependent, i.e., x86 or x64), when you can use the Application.DocumentManager Object which is native to .NET API and compile to AnyCPU... I forget which framework implements dynamics (4.0?), but that is yet another way of precluding environment dependency (early/late binding), whilst utilizing COM (if that's the route you really want to take).
Also, you may find the Autoloader Mechanism to be of use, here's a recent thread that may help.
Cheers
页:
[1]