Note that there are some explanatory texts on larger screens.

plurals
  1. PO
    primarykey
    data
    text
    <p>Judging by the link to <a href="http://discussion.autodesk.com/forums/thread.jspa?threadID=332207" rel="nofollow noreferrer">AutoDesk</a>'s forum on this topic, it sounds like as you need to close the object after saving...and remove the null's...If I were you, I'd wrap up the code into <code>try</code>/<code>catch</code> blocks to check and make sure there's no exception being thrown!</p> <p>I have to question the usage of the using clause, as you're <code>Launch</code>ing another copy aren't you? i.e. within the <code>OpenDrawing</code> and <code>Save</code> functions you are using <code>this._acadApplication</code> or have I misunderstood?</p> <pre> using (AutoCad cad = AutoCad.Instance) { try{ // Launch AutoCAD cad.Launch(); // Open drawing cad.OpenDrawing(@"C:\Scratch\Drawing01.dwg"); // Save it cad.SaveAs(@"C:\Scratch\Drawing01B.dwg"); }catch(COMException ex){ // Handle the exception here } } 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; // Comment ^^^ out? as you're instantiating an ActiveDocument below when opening the drawing? } public void OpenDrawing(string path) { try{ // 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; }catch(COMException ex){ // Handle the exception here } } public void SaveAs(string fullPath) { try{ this._acadDocument.SaveAs(fullPath, null, null); }catch(COMException ex){ // Handle the exception here }finally{ this._acadDocument.Close(); } } </pre> <p>Thought I'd include some links for your information. </p> <ul> <li>'<a href="http://through-the-interface.typepad.com/through_the_interface/2007/03/closing_all_ope.html" rel="nofollow noreferrer">Closing Autocad gracefully</a>'.</li> <li>'<a href="http://cupocadnet.blogspot.com/2009/06/migrating-autocad-com-api-applications.html" rel="nofollow noreferrer">Migrating AutoCAD COM to AutoCAD 2010</a>'.</li> <li>'<a href="http://www.objectarx.net/bbs/viewthread.php?action=printable&amp;tid=2735" rel="nofollow noreferrer">Saving AutoCAD to another format</a>'</li> </ul> <p>Hope this helps, Best regards, Tom.</p>
    singulars
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. VO
      singulars
      1. This table or related slice is empty.
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload