I am implementing an application that uses COM in the AutoCAD ObjectARX interface to automate drawing actions such as opening and saving as.
According to the documentation, I should be able to call AcadDocument.SaveAs () and pass the file name, "save as type" and security parameter. The documentation explicitly states that if the security value is NULL, no security-related operation is undertaken. However, this does not indicate that the correct type of the object is passed as the "save as type" parameter.
I tried calling SaveAs with the file name and null for the remaining arguments, but my application hangs in this method call, and AutoCAD crashes - you can still use the ribbon, but you can’t do anything using the toolbar and you can’t close AutoCAD.
I have the feeling that my NULL parameters are sad here, but the documentation in the COM / VBA department is very lacking. In fact, he says that the AcadDocument class does not even have a SaveAs method, which it explicitly does.
Has anyone here implemented the same thing? Any guidance?
An alternative is to use the SendCommand () method to send the _SAVEAS command, but my application controls the drawing batch and should know: a) if the failure fails, and b) when the save completes (that I'm listening to the EndSave event.)
EDIT
- , , AutoCAD ( , ), , (C:\Scratch\Document01B.dwg.)
using (AutoCad cad = AutoCad.Instance)
{
cad.Launch();
cad.OpenDrawing(@"C:\Scratch\Drawing01.dwg");
cad.SaveAs(@"C:\Scratch\Drawing01B.dwg");
}
AutoCad (this._acadDocument AcadDocument.)
public void Launch()
{
this._acadApplication = null;
const string ProgramId = "AutoCAD.Application.18";
try
{
this._acadApplication = (AcadApplication)Marshal.GetActiveObject(ProgramId);
}
catch (COMException)
{
try
{
this._acadApplication = (AcadApplication)Activator.CreateInstance(
Type.GetTypeFromProgID(ProgramId),
true);
}
catch (COMException exception)
{
throw new AutoCadNotFoundException(exception);
}
}
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
this._acadDocument = this._acadApplication.ActiveDocument;
}
public void OpenDrawing(string path)
{
this._acadApplication.Documents.Open(path, false, null);
this._acadDocument = this._acadApplication.ActiveDocument;
}
public void SaveAs(string fullPath)
{
this._acadDocument.SaveAs(fullPath, null, null);
}