<?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 LinetypeDialog with Linetypes from db.ReadDwgFile? in .NET Forum</title>
    <link>https://forums.autodesk.com/t5/net-forum/linetypedialog-with-linetypes-from-db-readdwgfile/m-p/13107854#M2165</link>
    <description>&lt;P&gt;Hello, good afternoon everyone,&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;is it possible to use the LinetypeDialog, e.g.&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;LI-CODE lang="csharp"&gt;LinetypeDialog dlgLinetype = new LinetypeDialog();
dlgLinetype.ShowDialog();
ObjectId idLinetype = dlgLinetype.Linetype;&lt;/LI-CODE&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;not in the context of the currently open dwg, but in relation to a dwg whose database is open in the background as follows?&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;LI-CODE lang="csharp"&gt;db.ReadDwgFile(strFileName, FileOpenMode.OpenForReadAndAllShare, false, null)&lt;/LI-CODE&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;What I'm wanting to get at is that in the LinetypeDialog the linetypes of the dwg are read, which is opened via db.ReadDwgFile.&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;Many thanks for an answer.&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
    <pubDate>Fri, 25 Oct 2024 10:06:44 GMT</pubDate>
    <dc:creator>doleischLG4UV</dc:creator>
    <dc:date>2024-10-25T10:06:44Z</dc:date>
    <item>
      <title>LinetypeDialog with Linetypes from db.ReadDwgFile?</title>
      <link>https://forums.autodesk.com/t5/net-forum/linetypedialog-with-linetypes-from-db-readdwgfile/m-p/13107854#M2165</link>
      <description>&lt;P&gt;Hello, good afternoon everyone,&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;is it possible to use the LinetypeDialog, e.g.&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;LI-CODE lang="csharp"&gt;LinetypeDialog dlgLinetype = new LinetypeDialog();
dlgLinetype.ShowDialog();
ObjectId idLinetype = dlgLinetype.Linetype;&lt;/LI-CODE&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;not in the context of the currently open dwg, but in relation to a dwg whose database is open in the background as follows?&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;LI-CODE lang="csharp"&gt;db.ReadDwgFile(strFileName, FileOpenMode.OpenForReadAndAllShare, false, null)&lt;/LI-CODE&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;What I'm wanting to get at is that in the LinetypeDialog the linetypes of the dwg are read, which is opened via db.ReadDwgFile.&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;Many thanks for an answer.&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Fri, 25 Oct 2024 10:06:44 GMT</pubDate>
      <guid>https://forums.autodesk.com/t5/net-forum/linetypedialog-with-linetypes-from-db-readdwgfile/m-p/13107854#M2165</guid>
      <dc:creator>doleischLG4UV</dc:creator>
      <dc:date>2024-10-25T10:06:44Z</dc:date>
    </item>
    <item>
      <title>Re: LinetypeDialog with Linetypes from db.ReadDwgFile?</title>
      <link>https://forums.autodesk.com/t5/net-forum/linetypedialog-with-linetypes-from-db-readdwgfile/m-p/13108020#M2166</link>
      <description>&lt;P&gt;Hi,&lt;/P&gt;
&lt;P&gt;To be able to show the LinetypeDialog from a side database, you have to this side database as working database (do not forget to restore the previous working database).&lt;/P&gt;
&lt;LI-CODE lang="csharp"&gt;var previousDatabase = HostApplicationServices.WorkingDatabase;
try
{
    using (var sideDatabase = new Database(false, true))
    {
        sideDatabase.ReadDwgFile(fileName, FileOpenMode.OpenForReadAndAllShare, false, null);
        HostApplicationServices.WorkingDatabase = sideDatabase;
        var dialog = new LinetypeDialog();
        dialog.ShowDialog();
        // ...
    }
}
finally
{
    HostApplicationServices.WorkingDatabase = previousDatabase;
}&lt;/LI-CODE&gt;</description>
      <pubDate>Fri, 25 Oct 2024 11:28:17 GMT</pubDate>
      <guid>https://forums.autodesk.com/t5/net-forum/linetypedialog-with-linetypes-from-db-readdwgfile/m-p/13108020#M2166</guid>
      <dc:creator>_gile</dc:creator>
      <dc:date>2024-10-25T11:28:17Z</dc:date>
    </item>
    <item>
      <title>Re: LinetypeDialog with Linetypes from db.ReadDwgFile?</title>
      <link>https://forums.autodesk.com/t5/net-forum/linetypedialog-with-linetypes-from-db-readdwgfile/m-p/13108415#M2167</link>
      <description>&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;Hi Gilles,&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;Thank you very much for your quick and helpful reply and the example shown.&amp;nbsp;&lt;span class="lia-unicode-emoji" title=":ok_hand:"&gt;👌&lt;/span&gt;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;It worked for me exactly as you listed.&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;Have a nice evening and a nice weekend!&amp;nbsp;&lt;span class="lia-unicode-emoji" title=":smiling_face_with_smiling_eyes:"&gt;😊&lt;/span&gt;&lt;/P&gt;</description>
      <pubDate>Fri, 25 Oct 2024 14:20:38 GMT</pubDate>
      <guid>https://forums.autodesk.com/t5/net-forum/linetypedialog-with-linetypes-from-db-readdwgfile/m-p/13108415#M2167</guid>
      <dc:creator>doleischLG4UV</dc:creator>
      <dc:date>2024-10-25T14:20:38Z</dc:date>
    </item>
    <item>
      <title>Re: LinetypeDialog with Linetypes from db.ReadDwgFile?</title>
      <link>https://forums.autodesk.com/t5/net-forum/linetypedialog-with-linetypes-from-db-readdwgfile/m-p/13108892#M2168</link>
      <description>&lt;P&gt;Instead of having to remember to restore the previous working database, and because having to temporarily change the working database is fairly-common, you can use the simple helper class and extension method below to simplify your application code and reduce the chances of bugs creeping in. The helper classes exploit the Disposable pattern to avoid the need to have to remember to undo something that your code does when its finished.&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;Example code like that posted by&amp;nbsp;&lt;a href="https://forums.autodesk.com/t5/user/viewprofilepage/user-id/109424"&gt;@_gile&lt;/a&gt;&amp;nbsp;is good for helping someone understand the basic API usage, but it would be a mistake to misinterpret example code snippets as being&amp;nbsp; good examples of how you should design and write real code, because example code snippets are usually very poor examples of that.&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;So, taking a &lt;A href="https://chatgpt.com/share/671bf212-7b84-8008-8251-dbd55a415a59" target="_blank" rel="noopener"&gt;more-holistic approach&lt;/A&gt; using the helper classes below, your code would become:&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;LI-CODE lang="csharp"&gt;using(Database db = new Database(false, true))
{
   db.ReadDwgFile(fileName, FileOpenMode.OpenForReadAndAllShare, false, null);
   using(db.AsWorkingDatabase())
   {
      var dialog = new LinetypeDialog();
      dialog.ShowDialog();
      /// ....
   }          // the previous working database is restored here
}&lt;/LI-CODE&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;The reusable helper classes:&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;LI-CODE lang="csharp"&gt;public class WorkingDatabase : IDisposable
{
   Database previous;

   public WorkingDatabase(Database newWorkingDb)
   {
      if(newWorkingDb == null)
         throw new ArgumentNullException(nameof(newWorkingDb));
      Database current = HostApplicationServices.WorkingDatabase;
      if(newWorkingDb != current)
      {
         previous = current;
         HostApplicationServices.WorkingDatabase = newWorkingDb;
      }
   }

   public void Dispose()
   {
      if(previous != null)
      {
         HostApplicationServices.WorkingDatabase = previous;
         previous = null;
      }
   }
}

public static partial class DatabaseExtensions
{
   public static IDisposable AsWorkingDatabase(this Database db)
   {
      return new WorkingDatabase(db);
   }
}&lt;/LI-CODE&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Fri, 25 Oct 2024 19:32:35 GMT</pubDate>
      <guid>https://forums.autodesk.com/t5/net-forum/linetypedialog-with-linetypes-from-db-readdwgfile/m-p/13108892#M2168</guid>
      <dc:creator>ActivistInvestor</dc:creator>
      <dc:date>2024-10-25T19:32:35Z</dc:date>
    </item>
    <item>
      <title>Re: LinetypeDialog with Linetypes from db.ReadDwgFile?</title>
      <link>https://forums.autodesk.com/t5/net-forum/linetypedialog-with-linetypes-from-db-readdwgfile/m-p/13112254#M2169</link>
      <description>&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;Thank you very much for your optimized solution to use general helper classes in such a case and to improve the code design. This is very helpful for me.&amp;nbsp;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;Best regards&amp;nbsp;&amp;nbsp;&lt;span class="lia-unicode-emoji" title=":smiling_face_with_smiling_eyes:"&gt;😊&lt;/span&gt;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Mon, 28 Oct 2024 07:37:44 GMT</pubDate>
      <guid>https://forums.autodesk.com/t5/net-forum/linetypedialog-with-linetypes-from-db-readdwgfile/m-p/13112254#M2169</guid>
      <dc:creator>doleischLG4UV</dc:creator>
      <dc:date>2024-10-28T07:37:44Z</dc:date>
    </item>
  </channel>
</rss>

