<?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: Inserting A Table into a Side Database in .NET Forum</title>
    <link>https://forums.autodesk.com/t5/net-forum/inserting-a-table-into-a-side-database/m-p/9847978#M18065</link>
    <description>&lt;P&gt;&lt;a href="https://forums.autodesk.com/t5/user/viewprofilepage/user-id/109424"&gt;@_gile&lt;/a&gt;&amp;nbsp; Removing the tb.GenerateLayout solved the issue! Seems to be working perfectly now.&lt;BR /&gt;Thanks for the help.&lt;/P&gt;</description>
    <pubDate>Thu, 05 Nov 2020 13:50:00 GMT</pubDate>
    <dc:creator>jschierenbeck</dc:creator>
    <dc:date>2020-11-05T13:50:00Z</dc:date>
    <item>
      <title>Inserting A Table into a Side Database</title>
      <link>https://forums.autodesk.com/t5/net-forum/inserting-a-table-into-a-side-database/m-p/9846094#M18061</link>
      <description>&lt;P&gt;My goal is to create a BOM table and insert it to a new drawing, without opening the new drawing.&lt;BR /&gt;My approach is to create a new database from a template drawing, then add the table to the new database.&lt;BR /&gt;&lt;BR /&gt;I am able to get everything to work when I insert the table to the active drawing, but when I try and use a side database it does not insert the table.&lt;BR /&gt;Am I doing something wrong here?&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;Attached is my Code&lt;/P&gt;</description>
      <pubDate>Wed, 04 Nov 2020 19:21:57 GMT</pubDate>
      <guid>https://forums.autodesk.com/t5/net-forum/inserting-a-table-into-a-side-database/m-p/9846094#M18061</guid>
      <dc:creator>jschierenbeck</dc:creator>
      <dc:date>2020-11-04T19:21:57Z</dc:date>
    </item>
    <item>
      <title>Re: Inserting A Table into a Side Database</title>
      <link>https://forums.autodesk.com/t5/net-forum/inserting-a-table-into-a-side-database/m-p/9846174#M18062</link>
      <description>&lt;P&gt;Hi,&lt;/P&gt;
&lt;P&gt;When you create a new Database for reading a dwg file (db.ReadDwgFile) you have to use false for the buildDefaultDrawing argument. And you do not need to do it twice.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;Try like this (not tested):&lt;/P&gt;
&lt;LI-CODE lang="csharp"&gt;            using (DocumentLock acLckDoc = acdoc.LockDocument())
            {
                using (var newDb = new Database(false, true))
                {
                    //Create a new .dwg using a template drawing.
                    newDb.ReadDwgFile(dwgtemplate, FileOpenMode.OpenForReadAndAllShare, false, null);
                
                    // Start a transaction in the new database
                    using (Transaction acTrans = newDb.TransactionManager.StartTransaction())
                    {
                        // Import the Excel BOM as a datatable.
                        System.Data.DataTable bomDT = Excel.LoadCSVFile(dwgBOMCSV);
                        int totalRows = bomDT.Rows.Count;
                        totalRows += 2;

                        string[,] bomArray = new string[totalRows, 4];
                        bomArray[1, 0] = "TAG";
                        bomArray[1, 1] = "DESCRIPTION";
                        bomArray[1, 2] = "CATALOG";
                        bomArray[1, 3] = "QTY";

                        int i = 2;
                        // Load the datatable into an array
                        foreach (DataRow item in bomDT.Rows)
                        {
                            var tag = item[0].ToString();
                            var description = item[1].ToString();
                            var catalog = item[2].ToString();
                            var qty = item[3].ToString();
                            ed.WriteMessage("\n" + item[2]);

                            bomArray[i, 0] = tag;
                            bomArray[i, 1] = description;
                            bomArray[i, 2] = catalog;
                            bomArray[i, 3] = qty;
                            i += 1;
                        }
                        var bt = acTrans.GetObject(newDb.BlockTableId, OpenMode.ForRead) as BlockTable;
                        var tb = new Table();
                        
                        tb.TableStyle = newDb.Tablestyle;
                        // insert rows and columns
                        totalRows -= 1;
                        tb.InsertRows(1, .2533, totalRows);
                        tb.InsertColumns(0, 2, 1);
                        tb.InsertColumns(0, 7, 1);
                        tb.InsertColumns(0, 2, 1);

                        tb.Position = new Point3d(1.5, 22, 0);
                        totalRows += 1;
                        for (int a = 1; a &amp;lt; totalRows; a++)
                        {
                            for (int b = 0; b &amp;lt; 4; b++)
                            {
                                string itemToInsert = bomArray[a, b];
                                tb.Cells[a, b].TextHeight = .1033;
                                tb.Cells[a, b].TextString = itemToInsert;
                                tb.Cells[a, b].Alignment = CellAlignment.MiddleCenter;
                            }
                        }

                        tb.GenerateLayout();
                        var btr = acTrans.GetObject(bt[BlockTableRecord.ModelSpace], OpenMode.ForWrite) as BlockTableRecord;
                        btr.AppendEntity(tb);
                        acTrans.AddNewlyCreatedDBObject(tb, true);
                        acTrans.Commit();
                                                                                                      
                    }
                    newDb.SaveAs(bomDwg, DwgVersion.Current);                                          
                }
            }
            HostApplicationServices.WorkingDatabase = acDb;
        }   &lt;/LI-CODE&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Wed, 04 Nov 2020 20:05:38 GMT</pubDate>
      <guid>https://forums.autodesk.com/t5/net-forum/inserting-a-table-into-a-side-database/m-p/9846174#M18062</guid>
      <dc:creator>_gile</dc:creator>
      <dc:date>2020-11-04T20:05:38Z</dc:date>
    </item>
    <item>
      <title>Re: Inserting A Table into a Side Database</title>
      <link>https://forums.autodesk.com/t5/net-forum/inserting-a-table-into-a-side-database/m-p/9846237#M18063</link>
      <description>&lt;P&gt;&lt;a href="https://forums.autodesk.com/t5/user/viewprofilepage/user-id/109424"&gt;@_gile&lt;/a&gt;&amp;nbsp; Thanks for the quick response!&lt;/P&gt;&lt;P&gt;I tried the code you gave me, but it still does the same thing.&lt;BR /&gt;It creates the new drawing, but no table is inserted.&amp;nbsp;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;If I insert the table on the active drawing (using the active drawing database instead of "newDb") it works perfectly.&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Wed, 04 Nov 2020 20:30:34 GMT</pubDate>
      <guid>https://forums.autodesk.com/t5/net-forum/inserting-a-table-into-a-side-database/m-p/9846237#M18063</guid>
      <dc:creator>jschierenbeck</dc:creator>
      <dc:date>2020-11-04T20:30:34Z</dc:date>
    </item>
    <item>
      <title>Re: Inserting A Table into a Side Database</title>
      <link>https://forums.autodesk.com/t5/net-forum/inserting-a-table-into-a-side-database/m-p/9847066#M18064</link>
      <description>&lt;P&gt;Try removing db.generateLayout(); or displacing it after the table is added to the transaction.&lt;/P&gt;</description>
      <pubDate>Thu, 05 Nov 2020 06:58:13 GMT</pubDate>
      <guid>https://forums.autodesk.com/t5/net-forum/inserting-a-table-into-a-side-database/m-p/9847066#M18064</guid>
      <dc:creator>_gile</dc:creator>
      <dc:date>2020-11-05T06:58:13Z</dc:date>
    </item>
    <item>
      <title>Re: Inserting A Table into a Side Database</title>
      <link>https://forums.autodesk.com/t5/net-forum/inserting-a-table-into-a-side-database/m-p/9847978#M18065</link>
      <description>&lt;P&gt;&lt;a href="https://forums.autodesk.com/t5/user/viewprofilepage/user-id/109424"&gt;@_gile&lt;/a&gt;&amp;nbsp; Removing the tb.GenerateLayout solved the issue! Seems to be working perfectly now.&lt;BR /&gt;Thanks for the help.&lt;/P&gt;</description>
      <pubDate>Thu, 05 Nov 2020 13:50:00 GMT</pubDate>
      <guid>https://forums.autodesk.com/t5/net-forum/inserting-a-table-into-a-side-database/m-p/9847978#M18065</guid>
      <dc:creator>jschierenbeck</dc:creator>
      <dc:date>2020-11-05T13:50:00Z</dc:date>
    </item>
  </channel>
</rss>

