<?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: ReadDwgFile from stream in .NET Forum</title>
    <link>https://forums.autodesk.com/t5/net-forum/readdwgfile-from-stream/m-p/9605073#M19195</link>
    <description>&lt;P&gt;You would save the Stream as DWG file in the local disk, and then read it into the new Database. You would delete it afterwards, if necessary.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;Since your code is AutoCAD add-in and AutoCAD itself uses temporary files a lot. The best practice would be to obtain AutoCAD's temporary file location from current running profile (accessing it via Application.Preferences property), so that your code would have the permission to save/delete temporary file.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
    <pubDate>Sat, 27 Jun 2020 12:00:25 GMT</pubDate>
    <dc:creator>norman.yuan</dc:creator>
    <dc:date>2020-06-27T12:00:25Z</dc:date>
    <item>
      <title>ReadDwgFile from stream</title>
      <link>https://forums.autodesk.com/t5/net-forum/readdwgfile-from-stream/m-p/9604682#M19192</link>
      <description>&lt;P&gt;Hello&lt;/P&gt;&lt;P&gt;I have a drawing file containing some standard blocks. Using this snippet to read drawing from a memory stream:&lt;/P&gt;&lt;LI-CODE lang="csharp"&gt;                using (Stream fs = Assembly.GetExecutingAssembly().GetManifestResourceStream("Resources.StandardBlocks.dwg"))
                {
                    using (MemoryStream ms = new MemoryStream())
                    {
                        fs.CopyTo(ms);
                        byte[] bts = ms.ToArray();

                        GCHandle pinnedArray = GCHandle.Alloc(bts, GCHandleType.Pinned);
                        IntPtr pointer = pinnedArray.AddrOfPinnedObject();
                        Database sourceDb = new Database(false, true);
                        try
                        {
                            sourceDb.ReadDwgFile(pointer, false, "");
                        }
                        catch(System.Exception e)
                        {

                        }
// Some code to work with sourceDb
                        sourceDb.Dispose();
                        pinnedArray.Free();

                    }
                }&lt;/LI-CODE&gt;&lt;P&gt;The point is that: when code reaches ReadDwgFile, autocad crashes without&amp;nbsp; even reaching to catch statement.&lt;/P&gt;&lt;P&gt;if it helps, standardBlocks.dwg contains a block of an OLE excel sheet.&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;Could you please help&lt;/P&gt;</description>
      <pubDate>Fri, 26 Jun 2020 22:41:06 GMT</pubDate>
      <guid>https://forums.autodesk.com/t5/net-forum/readdwgfile-from-stream/m-p/9604682#M19192</guid>
      <dc:creator>Ahmadi_rad</dc:creator>
      <dc:date>2020-06-26T22:41:06Z</dc:date>
    </item>
    <item>
      <title>Re: ReadDwgFile from stream</title>
      <link>https://forums.autodesk.com/t5/net-forum/readdwgfile-from-stream/m-p/9604826#M19193</link>
      <description>The ReadDwgFile() method that takes an IntPtr as the first argument expects the IntPtr to be a pointer to an object of one of our internal C++ classes used for reading dwg files.  The code static_casts the pointer to that type, so if the object isn't that type, then there will be problems such as what you've experienced.</description>
      <pubDate>Sat, 27 Jun 2020 03:12:53 GMT</pubDate>
      <guid>https://forums.autodesk.com/t5/net-forum/readdwgfile-from-stream/m-p/9604826#M19193</guid>
      <dc:creator>artc2</dc:creator>
      <dc:date>2020-06-27T03:12:53Z</dc:date>
    </item>
    <item>
      <title>Re: ReadDwgFile from stream</title>
      <link>https://forums.autodesk.com/t5/net-forum/readdwgfile-from-stream/m-p/9604890#M19194</link>
      <description>&lt;P&gt;thanks for reply&lt;/P&gt;&lt;P&gt;So, How can I use a memory stream for that purpose? I don't directly have a file, whatever it is, it is stored in database or embedded resource in project.&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Sat, 27 Jun 2020 06:37:51 GMT</pubDate>
      <guid>https://forums.autodesk.com/t5/net-forum/readdwgfile-from-stream/m-p/9604890#M19194</guid>
      <dc:creator>Ahmadi_rad</dc:creator>
      <dc:date>2020-06-27T06:37:51Z</dc:date>
    </item>
    <item>
      <title>Re: ReadDwgFile from stream</title>
      <link>https://forums.autodesk.com/t5/net-forum/readdwgfile-from-stream/m-p/9605073#M19195</link>
      <description>&lt;P&gt;You would save the Stream as DWG file in the local disk, and then read it into the new Database. You would delete it afterwards, if necessary.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;Since your code is AutoCAD add-in and AutoCAD itself uses temporary files a lot. The best practice would be to obtain AutoCAD's temporary file location from current running profile (accessing it via Application.Preferences property), so that your code would have the permission to save/delete temporary file.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Sat, 27 Jun 2020 12:00:25 GMT</pubDate>
      <guid>https://forums.autodesk.com/t5/net-forum/readdwgfile-from-stream/m-p/9605073#M19195</guid>
      <dc:creator>norman.yuan</dc:creator>
      <dc:date>2020-06-27T12:00:25Z</dc:date>
    </item>
    <item>
      <title>Re: ReadDwgFile from stream</title>
      <link>https://forums.autodesk.com/t5/net-forum/readdwgfile-from-stream/m-p/9606044#M19196</link>
      <description>&lt;P&gt;Thanks&lt;/P&gt;&lt;P&gt;I found &lt;A href="https://knowledge.autodesk.com/de/support/autocad/learn-explore/caas/CloudHelp/cloudhelp/2016/DEU/AutoCAD-NET/files/GUID-7E1AC51A-CDD6-4CD5-8703-3D3A472BFFC5-htm.html" target="_blank" rel="noopener"&gt;this post&lt;/A&gt; about using preferences object.&amp;nbsp;&lt;/P&gt;&lt;P&gt;But in my visual studio, I can't find class of&amp;nbsp;AcadPreferences as shown in sample. Which dll shall I add to references?&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Sun, 28 Jun 2020 11:46:47 GMT</pubDate>
      <guid>https://forums.autodesk.com/t5/net-forum/readdwgfile-from-stream/m-p/9606044#M19196</guid>
      <dc:creator>Ahmadi_rad</dc:creator>
      <dc:date>2020-06-28T11:46:47Z</dc:date>
    </item>
    <item>
      <title>Re: ReadDwgFile from stream</title>
      <link>https://forums.autodesk.com/t5/net-forum/readdwgfile-from-stream/m-p/9606065#M19197</link>
      <description>&lt;P&gt;I think you can easy use &lt;A href="https://docs.microsoft.com/en-us/dotnet/api/system.io.path.gettempfilename?view=netcore-3.1" target="_blank" rel="noopener"&gt;Path.GetTempFileName()&lt;/A&gt;&lt;/P&gt;</description>
      <pubDate>Sun, 28 Jun 2020 12:23:54 GMT</pubDate>
      <guid>https://forums.autodesk.com/t5/net-forum/readdwgfile-from-stream/m-p/9606065#M19197</guid>
      <dc:creator>Alexander.Rivilis</dc:creator>
      <dc:date>2020-06-28T12:23:54Z</dc:date>
    </item>
  </channel>
</rss>

