AutoCAD の ObjectARX インターフェイスで COM を使用して、開く、名前を付けて保存などの描画アクションを自動化するアプリケーションを実装しています。
ドキュメントによると、AcadDocument.SaveAs() を呼び出して、ファイル名、「ファイルの種類」、およびセキュリティ パラメータを渡すことができるはずです。ドキュメントには、セキュリティが NULL の場合、セキュリティ関連の操作は試行されないことが明示的に記載されています。ただし、「タイプとして保存」パラメータとして渡す正しいオブジェクト タイプは示されません。
ファイル名を指定し、残りの引数に null を指定して SaveAs を呼び出してみましたが、アプリケーションがそのメソッド呼び出しでハングし、AutoCAD がクラッシュしたように見えます。リボンは引き続き使用できますが、ツールバーで何もできず、閉じることもできません。オートキャド。
ここで悲しみを引き起こしているのは私の NULL パラメーターであると感じていますが、COM/VBA 部門にはドキュメントが大幅に不足しています。実際、AcadDocument クラスには SaveAs メソッドさえないと言われていますが、それは明らかにあります。
ここで誰かが同じことを実装しましたか? ガイダンスはありますか?
別の方法として、SendCommand() メソッドを使用して _SAVEAS コマンドを送信しますが、私のアプリケーションは描画のバッチを管理しており、a) 保存が失敗したかどうか、および b) 保存がいつ完了したかを知る必要があります (これは私が行っていることです)。 EndSave イベントをリッスンします。)
編集
要求されたコードは次のとおりです。実行しているのは、AutoCAD を起動し (または、既に実行されている場合は実行中のインスタンスに接続し)、既存の図面を開き、ドキュメントを新しい場所 (C:\Scratch\Document01B.dwg.) に保存することだけです。
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");
}
次に、AutoCad クラスで (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);
}