<?xml version="1.0" encoding="UTF-8"?>
<rss xmlns:content="http://purl.org/rss/1.0/modules/content/" xmlns:dc="http://purl.org/dc/elements/1.1/" xmlns:rdf="http://www.w3.org/1999/02/22-rdf-syntax-ns#" xmlns:taxo="http://purl.org/rss/1.0/modules/taxonomy/" version="2.0">
  <channel>
    <title>topic Re: AutoCAD auto exited after calling SaveAs method for a nodocument database in .NET Forum</title>
    <link>https://forums.autodesk.com/t5/net-forum/autocad-auto-exited-after-calling-saveas-method-for-a-nodocument/m-p/11348530#M12113</link>
    <description>&lt;P&gt;You have to restore previous value of HostApplicationServices.WorkingDatabase&lt;/P&gt;</description>
    <pubDate>Tue, 09 Aug 2022 11:16:27 GMT</pubDate>
    <dc:creator>Alexander.Rivilis</dc:creator>
    <dc:date>2022-08-09T11:16:27Z</dc:date>
    <item>
      <title>AutoCAD auto exited after calling SaveAs method for a nodocument database</title>
      <link>https://forums.autodesk.com/t5/net-forum/autocad-auto-exited-after-calling-saveas-method-for-a-nodocument/m-p/11348404#M12112</link>
      <description>&lt;P&gt;I'm writing a service that creates and returns a dwg file to end user.&lt;BR /&gt;What I expected is that an AutoCAD instance working on the same computer of the service and listen to a specified command. Whenever receives the command, the command handler will create a new database with buildDefaultDrwaing(true) and noDocument(true), append some entities to modelspace, then save this database to computer's temp folder.&lt;BR /&gt;However, the AutoCAD instance exits after the SaveAs method called every time.&lt;BR /&gt;Here is the code:&lt;/P&gt;&lt;LI-CODE lang="general"&gt;        [CommandMethod("testcode", CommandFlags.Modal)]
        public void TestCode()
        {
            try
            {
                using (var database = new Database(true, true))
                {
                    HostApplicationServices.WorkingDatabase = database;
                    using (var acTrans = database.TransactionManager.StartTransaction())
                    {
                        var modelSpace = acTrans.GetObject(SymbolUtilityServices.GetBlockModelSpaceId(database),
                                OpenMode.ForWrite) as
                            BlockTableRecord;

                        var dim = new AlignedDimension(new Point3d(0, 0, 0), new Point3d(10, 0, 0),
                            new Point3d(10, 0, 0), "", ObjectId.Null);
                        modelSpace.AppendEntity(dim);
                        acTrans.AddNewlyCreatedDBObject(dim, true);

                        acTrans.Commit();
                    }

                    //
                    var path = Path.GetTempFileName().Replace(".tmp", ".dwg");
                    database.SaveAs(path, DwgVersion.AC1027);
                }
            }
            catch (Exception e)
            {
                Console.WriteLine(e);
                throw;
            }
            catch (System.Exception e)
            {
                Console.WriteLine(e.Message);
            }
        }&lt;/LI-CODE&gt;</description>
      <pubDate>Tue, 09 Aug 2022 10:02:04 GMT</pubDate>
      <guid>https://forums.autodesk.com/t5/net-forum/autocad-auto-exited-after-calling-saveas-method-for-a-nodocument/m-p/11348404#M12112</guid>
      <dc:creator>lijingyaJPJMV</dc:creator>
      <dc:date>2022-08-09T10:02:04Z</dc:date>
    </item>
    <item>
      <title>Re: AutoCAD auto exited after calling SaveAs method for a nodocument database</title>
      <link>https://forums.autodesk.com/t5/net-forum/autocad-auto-exited-after-calling-saveas-method-for-a-nodocument/m-p/11348530#M12113</link>
      <description>&lt;P&gt;You have to restore previous value of HostApplicationServices.WorkingDatabase&lt;/P&gt;</description>
      <pubDate>Tue, 09 Aug 2022 11:16:27 GMT</pubDate>
      <guid>https://forums.autodesk.com/t5/net-forum/autocad-auto-exited-after-calling-saveas-method-for-a-nodocument/m-p/11348530#M12113</guid>
      <dc:creator>Alexander.Rivilis</dc:creator>
      <dc:date>2022-08-09T11:16:27Z</dc:date>
    </item>
  </channel>
</rss>

