我正在实现一个应用程序,它在AutoCAD的ObjectARX界面中使用COM自动执行绘图操作,例如打开并另存为。SaveAs在COM中悬挂AutoCAD
根据文档,我应该能够调用AcadDocument.SaveAs()并传入文件名,“另存为类型”和一个安全参数。该文档明确表明,如果安全性为NULL,则不会尝试执行与安全性相关的操作。但是,它并没有给出正确的对象类型作为“另存为类型”参数传递的任何指示。
我试过使用文件名调用SaveAs,其余参数为null,但是我的应用程序挂在那个方法调用上,而AutoCAD似乎崩溃 - 您仍然可以使用功能区,但无法对工具栏执行任何操作无法关闭AutoCAD。
我有一种感觉,这是我的NULL参数导致悲伤在这里,但在COM/VBA部门严重缺乏文档。实际上它说AcadDocument类甚至没有SaveAs方法,这显然是。
有没有人在这里执行过同样的事情?任何指导?
另一种方法是使用SendCommand()方法发送_SAVEAS命令,但我的应用程序正在管理一批绘图,并需要知道a)如果保存失败,并且b)保存完成时(其中I “M通过听取EndSave事件做)
编辑
这里所要求的代码 - 所有它做的是推出的AutoCAD(或连接到正在运行的实例,如果它已经运行),打开现有绘图,然后将文档保存到新位置(C:\ Scratch \ Document01B.dwg。)
我的AutoCad类using (AutoCad cad = AutoCad.Instance)
{
// Launch AutoCAD
cad.Launch();
// Open drawing
cad.OpenDrawing(@"C:\Scratch\Drawing01.dwg");
// Save it
cad.SaveAs(@"C:\Scratch\Drawing01B.dwg");
}
然后(this._acadDocument是AcadDocument类的一个实例。)
public void Launch()
{
this._acadApplication = null;
const string ProgramId = "AutoCAD.Application.18";
try
{
// Connect to a running instance
this._acadApplication = (AcadApplication)Marshal.GetActiveObject(ProgramId);
}
catch (COMException)
{
/* No instance running, launch one */
try
{
this._acadApplication = (AcadApplication)Activator.CreateInstance(
Type.GetTypeFromProgID(ProgramId),
true);
}
catch (COMException exception)
{
// Failed - is AutoCAD installed?
throw new AutoCadNotFoundException(exception);
}
}
/* Listen for the events we need and make the application visible */
this._acadApplication.BeginOpen += this.OnAcadBeginOpen;
this._acadApplication.BeginSave += this.OnAcadBeginSave;
this._acadApplication.EndOpen += this.OnAcadEndOpen;
this._acadApplication.EndSave += this.OnAcadEndSave;
#if DEBUG
this._acadApplication.Visible = true;
#else
this._acadApplication.Visible = false;
#endif
// Get the active document
this._acadDocument = this._acadApplication.ActiveDocument;
}
public void OpenDrawing(string path)
{
// Request AutoCAD to open the document
this._acadApplication.Documents.Open(path, false, null);
// Update our reference to the new document
this._acadDocument = this._acadApplication.ActiveDocument;
}
public void SaveAs(string fullPath)
{
this._acadDocument.SaveAs(fullPath, null, null);
}
你可以显示代码吗? – t0mm13b 2010-02-18 10:47:21
@ tommieb75:已添加到问题 – 2010-02-18 11:14:20