<?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: DGNImport in .NET Forum</title>
    <link>https://forums.autodesk.com/t5/net-forum/dgnimport/m-p/2855044#M62654</link>
    <description>&lt;P&gt;Hi there,&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;I think your problem will besolved with net next block of code.&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;PRE&gt;[CommandMethod("DgnAttach")]
        static public void DgnAttach()
        {
            Database db = Application.DocumentManager.MdiActiveDocument.Database;
            using (Transaction trans = Application.DocumentManager.MdiActiveDocument.TransactionManager.StartTransaction())
            {                
                DBDictionary nod = (DBDictionary)trans.GetObject(db.NamedObjectsDictionaryId, OpenMode.ForWrite);
                string defDictKey = UnderlayDefinition.GetDictionaryKey(typeof(DgnDefinition));
                if (!nod.Contains(defDictKey))                
                {                    
                    using (DBDictionary dict = new DBDictionary())                    
                    {                        
                        nod.SetAt(defDictKey, dict);                        
                        trans.AddNewlyCreatedDBObject(dict, true);                    
                    }                
                }                
                ObjectId idDgnDef;                
                DBDictionary dgnDict = (DBDictionary)trans.GetObject(nod.GetAt(defDictKey), OpenMode.ForWrite);                
                using (DgnDefinition dgnDef = new DgnDefinition())                
                {                    
                    dgnDef.SourceFileName = @"c:\Temp\yourdgnfile.dgn";                    
                    idDgnDef = dgnDict.SetAt("YourDgnFile", dgnDef);                    
                    trans.AddNewlyCreatedDBObject(dgnDef, true);                
                }                
                BlockTable bt = (BlockTable)trans.GetObject(db.BlockTableId, OpenMode.ForRead);                
                BlockTableRecord btr = (BlockTableRecord)trans.GetObject(bt[BlockTableRecord.ModelSpace], OpenMode.ForWrite);                
                using (DgnReference dgn = new DgnReference())
                {                    
                    dgn.DefinitionId = idDgnDef;                    
                    btr.AppendEntity(dgn);
                    trans.AddNewlyCreatedDBObject(dgn, true);
                }                
                trans.Commit();           
            }        
        }&lt;/PRE&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;If you want to attach a dwf file the above code can be used. You just need to change the DgnDefinition to DwfDefinition ect.&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;I hope this helps.&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;Kind regards,&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;Irvin&lt;/P&gt;</description>
    <pubDate>Thu, 16 Dec 2010 08:26:40 GMT</pubDate>
    <dc:creator>Anonymous</dc:creator>
    <dc:date>2010-12-16T08:26:40Z</dc:date>
    <item>
      <title>DGNImport</title>
      <link>https://forums.autodesk.com/t5/net-forum/dgnimport/m-p/2854948#M62653</link>
      <description>&lt;P&gt;Hello All&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;Does anyone know if the functionallity used in the Command DGNImport is customisable via the API?&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;I've had a look but I can't seem to find it, but I know there are people out there with much more familiarity with it than me.&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;Thanks&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;Jason.&lt;/P&gt;</description>
      <pubDate>Thu, 16 Dec 2010 02:10:11 GMT</pubDate>
      <guid>https://forums.autodesk.com/t5/net-forum/dgnimport/m-p/2854948#M62653</guid>
      <dc:creator>Anonymous</dc:creator>
      <dc:date>2010-12-16T02:10:11Z</dc:date>
    </item>
    <item>
      <title>Re: DGNImport</title>
      <link>https://forums.autodesk.com/t5/net-forum/dgnimport/m-p/2855044#M62654</link>
      <description>&lt;P&gt;Hi there,&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;I think your problem will besolved with net next block of code.&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;PRE&gt;[CommandMethod("DgnAttach")]
        static public void DgnAttach()
        {
            Database db = Application.DocumentManager.MdiActiveDocument.Database;
            using (Transaction trans = Application.DocumentManager.MdiActiveDocument.TransactionManager.StartTransaction())
            {                
                DBDictionary nod = (DBDictionary)trans.GetObject(db.NamedObjectsDictionaryId, OpenMode.ForWrite);
                string defDictKey = UnderlayDefinition.GetDictionaryKey(typeof(DgnDefinition));
                if (!nod.Contains(defDictKey))                
                {                    
                    using (DBDictionary dict = new DBDictionary())                    
                    {                        
                        nod.SetAt(defDictKey, dict);                        
                        trans.AddNewlyCreatedDBObject(dict, true);                    
                    }                
                }                
                ObjectId idDgnDef;                
                DBDictionary dgnDict = (DBDictionary)trans.GetObject(nod.GetAt(defDictKey), OpenMode.ForWrite);                
                using (DgnDefinition dgnDef = new DgnDefinition())                
                {                    
                    dgnDef.SourceFileName = @"c:\Temp\yourdgnfile.dgn";                    
                    idDgnDef = dgnDict.SetAt("YourDgnFile", dgnDef);                    
                    trans.AddNewlyCreatedDBObject(dgnDef, true);                
                }                
                BlockTable bt = (BlockTable)trans.GetObject(db.BlockTableId, OpenMode.ForRead);                
                BlockTableRecord btr = (BlockTableRecord)trans.GetObject(bt[BlockTableRecord.ModelSpace], OpenMode.ForWrite);                
                using (DgnReference dgn = new DgnReference())
                {                    
                    dgn.DefinitionId = idDgnDef;                    
                    btr.AppendEntity(dgn);
                    trans.AddNewlyCreatedDBObject(dgn, true);
                }                
                trans.Commit();           
            }        
        }&lt;/PRE&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;If you want to attach a dwf file the above code can be used. You just need to change the DgnDefinition to DwfDefinition ect.&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;I hope this helps.&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;Kind regards,&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;Irvin&lt;/P&gt;</description>
      <pubDate>Thu, 16 Dec 2010 08:26:40 GMT</pubDate>
      <guid>https://forums.autodesk.com/t5/net-forum/dgnimport/m-p/2855044#M62654</guid>
      <dc:creator>Anonymous</dc:creator>
      <dc:date>2010-12-16T08:26:40Z</dc:date>
    </item>
    <item>
      <title>Re: DGNImport</title>
      <link>https://forums.autodesk.com/t5/net-forum/dgnimport/m-p/2856100#M62655</link>
      <description>&lt;P&gt;Irvin&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;Thank you for your reply.&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;However what I really need to do is to replicate some of the functionallity of the DGNIMPORT command not the DGNUNDERLAY (for which your code works perfectly for).&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;That is I need to translate the entities from the DGN file into native AutoCAD entities.&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;But once again thank you for your time.&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;Jason&lt;/P&gt;</description>
      <pubDate>Thu, 16 Dec 2010 23:39:50 GMT</pubDate>
      <guid>https://forums.autodesk.com/t5/net-forum/dgnimport/m-p/2856100#M62655</guid>
      <dc:creator>Anonymous</dc:creator>
      <dc:date>2010-12-16T23:39:50Z</dc:date>
    </item>
    <item>
      <title>Re: DGNImport</title>
      <link>https://forums.autodesk.com/t5/net-forum/dgnimport/m-p/3893926#M62656</link>
      <description>&lt;P&gt;Hi Jason,&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;I know I am replying to old thread. But have you got any success about translating the DGN entities to DWG?&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;I am working on the same thing, so your inputs are greatly appreciated.&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;Thanks,&lt;/P&gt;&lt;P&gt;Sandeep&lt;/P&gt;</description>
      <pubDate>Fri, 26 Apr 2013 06:26:52 GMT</pubDate>
      <guid>https://forums.autodesk.com/t5/net-forum/dgnimport/m-p/3893926#M62656</guid>
      <dc:creator>Anonymous</dc:creator>
      <dc:date>2013-04-26T06:26:52Z</dc:date>
    </item>
    <item>
      <title>Re: DGNImport</title>
      <link>https://forums.autodesk.com/t5/net-forum/dgnimport/m-p/3896425#M62657</link>
      <description>&lt;P&gt;Hi Sandeep&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;Unfortunately, no I did not have any success in this area.&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;Bentley are able to read in AutoCAD dwg format very well because of Autodesk's RealDWG. However I don't think they have anything similar to offer and AutoCAD's implementation of this doesn't seem to be public.&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;Sorry.&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;Jason&lt;/P&gt;</description>
      <pubDate>Mon, 29 Apr 2013 04:05:46 GMT</pubDate>
      <guid>https://forums.autodesk.com/t5/net-forum/dgnimport/m-p/3896425#M62657</guid>
      <dc:creator>Anonymous</dc:creator>
      <dc:date>2013-04-29T04:05:46Z</dc:date>
    </item>
    <item>
      <title>Re: DGNImport</title>
      <link>https://forums.autodesk.com/t5/net-forum/dgnimport/m-p/3899591#M62658</link>
      <description>&lt;P&gt;this will work.&amp;nbsp;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;For&lt;/P&gt;&lt;P&gt;&lt;FONT color="#0000ff" size="2"&gt;&lt;FONT color="#0000ff" size="2"&gt;Each&lt;/FONT&gt;&lt;/FONT&gt;&lt;FONT size="2"&gt; file &lt;/FONT&gt;&lt;FONT color="#0000ff" size="2"&gt;&lt;FONT color="#0000ff" size="2"&gt;As&lt;/FONT&gt;&lt;/FONT&gt;&lt;FONT size="2"&gt; System.IO.FileInfo &lt;/FONT&gt;&lt;FONT color="#0000ff" size="2"&gt;&lt;FONT color="#0000ff" size="2"&gt;In&lt;/FONT&gt;&lt;/FONT&gt;&lt;FONT size="2"&gt;&lt;FONT size="2"&gt;files&lt;/FONT&gt;&lt;/FONT&gt;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&lt;FONT color="#0000ff" size="2"&gt;&lt;FONT color="#0000ff" size="2"&gt;Try&lt;/FONT&gt;&lt;/FONT&gt;&lt;FONT color="#0000ff" size="2"&gt;&lt;FONT color="#0000ff" size="2"&gt;Dim&lt;/FONT&gt;&lt;/FONT&gt;&lt;FONT size="2"&gt; sfilename &lt;/FONT&gt;&lt;FONT color="#0000ff" size="2"&gt;&lt;FONT color="#0000ff" size="2"&gt;As&lt;/FONT&gt;&lt;/FONT&gt;&lt;FONT color="#0000ff" size="2"&gt;&lt;FONT color="#0000ff" size="2"&gt;String&lt;/FONT&gt;&lt;/FONT&gt;&lt;FONT size="2"&gt;&lt;FONT size="2"&gt;= file.FullName&lt;/FONT&gt;&lt;/FONT&gt;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&lt;FONT color="#0000ff" size="2"&gt;&lt;FONT color="#0000ff" size="2"&gt;Dim&lt;/FONT&gt;&lt;/FONT&gt;&lt;FONT size="2"&gt; sfilenamedwg &lt;/FONT&gt;&lt;FONT color="#0000ff" size="2"&gt;&lt;FONT color="#0000ff" size="2"&gt;As&lt;/FONT&gt;&lt;/FONT&gt;&lt;FONT color="#0000ff" size="2"&gt;&lt;FONT color="#0000ff" size="2"&gt;String&lt;/FONT&gt;&lt;/FONT&gt;&lt;FONT size="2"&gt; = mypath &amp;amp; System.IO.Path.GetFileNameWithoutExtension(sfilename) &amp;amp; &lt;/FONT&gt;&lt;FONT color="#a31515" size="2"&gt;&lt;FONT color="#a31515" size="2"&gt;".dwg"&lt;/FONT&gt;&lt;/FONT&gt;&lt;FONT color="#0000ff" size="2"&gt;&lt;FONT color="#0000ff" size="2"&gt;If&lt;/FONT&gt;&lt;/FONT&gt;&lt;FONT size="2"&gt; System.IO.File.Exists(sfilenamedwg) = &lt;/FONT&gt;&lt;FONT color="#0000ff" size="2"&gt;&lt;FONT color="#0000ff" size="2"&gt;True&lt;/FONT&gt;&lt;/FONT&gt;&lt;FONT color="#0000ff" size="2"&gt;&lt;FONT color="#0000ff" size="2"&gt;Then&lt;/FONT&gt;&lt;/FONT&gt;&lt;FONT size="2"&gt;&lt;FONT size="2"&gt;System.IO.File.Delete(sfilenamedwg)&lt;/FONT&gt;&lt;/FONT&gt;&lt;/P&gt;&lt;P&gt;Application.DocumentManager.MdiActiveDocument.SendStringToExecute(&lt;/P&gt;&lt;P&gt;&lt;FONT color="#a31515" size="2"&gt;&lt;FONT color="#a31515" size="2"&gt;"-dgnimport "&lt;/FONT&gt;&lt;/FONT&gt;&lt;FONT size="2"&gt; &amp;amp; sfilename &amp;amp; vbCr &amp;amp; vbCr &amp;amp; vbCr &amp;amp; vbCr, &lt;/FONT&gt;&lt;FONT color="#0000ff" size="2"&gt;&lt;FONT color="#0000ff" size="2"&gt;False&lt;/FONT&gt;&lt;/FONT&gt;&lt;FONT size="2"&gt;, &lt;/FONT&gt;&lt;FONT color="#0000ff" size="2"&gt;&lt;FONT color="#0000ff" size="2"&gt;False&lt;/FONT&gt;&lt;/FONT&gt;&lt;FONT size="2"&gt;, &lt;/FONT&gt;&lt;FONT color="#0000ff" size="2"&gt;&lt;FONT color="#0000ff" size="2"&gt;True&lt;/FONT&gt;&lt;/FONT&gt;&lt;FONT size="2"&gt;&lt;FONT size="2"&gt;)&lt;/FONT&gt;&lt;/FONT&gt;&lt;/P&gt;&lt;P&gt;Application.DocumentManager.MdiActiveDocument.SendStringToExecute(&lt;/P&gt;&lt;P&gt;&lt;FONT color="#a31515" size="2"&gt;&lt;FONT color="#a31515" size="2"&gt;"saveas"&lt;/FONT&gt;&lt;/FONT&gt;&lt;FONT size="2"&gt; &amp;amp; vbCr &amp;amp; vbCr &amp;amp; sfilenamedwg &amp;amp; vbCr, &lt;/FONT&gt;&lt;FONT color="#0000ff" size="2"&gt;&lt;FONT color="#0000ff" size="2"&gt;False&lt;/FONT&gt;&lt;/FONT&gt;&lt;FONT size="2"&gt;, &lt;/FONT&gt;&lt;FONT color="#0000ff" size="2"&gt;&lt;FONT color="#0000ff" size="2"&gt;False&lt;/FONT&gt;&lt;/FONT&gt;&lt;FONT size="2"&gt;, &lt;/FONT&gt;&lt;FONT color="#0000ff" size="2"&gt;&lt;FONT color="#0000ff" size="2"&gt;True&lt;/FONT&gt;&lt;/FONT&gt;&lt;FONT size="2"&gt;&lt;FONT size="2"&gt;)&lt;/FONT&gt;&lt;/FONT&gt;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&lt;FONT color="#0000ff" size="2"&gt;&lt;FONT color="#0000ff" size="2"&gt;Catch&lt;/FONT&gt;&lt;/FONT&gt;&lt;FONT size="2"&gt; ex &lt;/FONT&gt;&lt;FONT color="#0000ff" size="2"&gt;&lt;FONT color="#0000ff" size="2"&gt;As&lt;/FONT&gt;&lt;/FONT&gt;&lt;FONT size="2"&gt;&lt;FONT size="2"&gt;Exception&lt;/FONT&gt;&lt;/FONT&gt;&lt;/P&gt;&lt;P&gt;MsgBox(ex.ToString)&lt;/P&gt;&lt;P&gt;&lt;FONT color="#0000ff" size="2"&gt;&lt;FONT color="#0000ff" size="2"&gt;End&lt;/FONT&gt;&lt;/FONT&gt;&lt;FONT color="#0000ff" size="2"&gt;&lt;FONT color="#0000ff" size="2"&gt;Try&lt;/FONT&gt;&lt;/FONT&gt;&lt;FONT color="#0000ff" size="2"&gt;&lt;FONT color="#0000ff" size="2"&gt;Next&lt;/FONT&gt;&lt;/FONT&gt;&lt;/P&gt;</description>
      <pubDate>Tue, 30 Apr 2013 16:07:43 GMT</pubDate>
      <guid>https://forums.autodesk.com/t5/net-forum/dgnimport/m-p/3899591#M62658</guid>
      <dc:creator>michael_vanhoose</dc:creator>
      <dc:date>2013-04-30T16:07:43Z</dc:date>
    </item>
    <item>
      <title>Re: DGNImport</title>
      <link>https://forums.autodesk.com/t5/net-forum/dgnimport/m-p/4347183#M62659</link>
      <description>Yes michael.vanhoose code really works fine&lt;BR /&gt;&lt;BR /&gt;Thanks man</description>
      <pubDate>Tue, 30 Jul 2013 06:31:05 GMT</pubDate>
      <guid>https://forums.autodesk.com/t5/net-forum/dgnimport/m-p/4347183#M62659</guid>
      <dc:creator>Anonymous</dc:creator>
      <dc:date>2013-07-30T06:31:05Z</dc:date>
    </item>
  </channel>
</rss>

