<?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: Insert existing block into DWG C# in .NET Forum</title>
    <link>https://forums.autodesk.com/t5/net-forum/insert-existing-block-into-dwg-c/m-p/2006012#M77649</link>
    <description>What you have looks close enough, you *might need to alter it a bit, but the basis is correct.&lt;BR /&gt;
&lt;BR /&gt;
I would suggest: &lt;BR /&gt;
--Try to open bt with ForRead access. It may not require write access.&lt;BR /&gt;
--Use:  if(bt.Has("V1"))  as a "block exists" check.&lt;BR /&gt;
--Create the reference directly via: acadDb.BlockReference br = New acadDb.BlockReference(pos, bt["V1"])&lt;BR /&gt;
&lt;BR /&gt;
Of course, if the block doesn't exist you can load it from another drawing. Try working with the AcDb.Database methods: ReadDwgFile(), Insert() and WblockCloneObjects().</description>
    <pubDate>Wed, 27 Jun 2007 22:15:28 GMT</pubDate>
    <dc:creator>jbooth</dc:creator>
    <dc:date>2007-06-27T22:15:28Z</dc:date>
    <item>
      <title>Insert existing block into DWG C#</title>
      <link>https://forums.autodesk.com/t5/net-forum/insert-existing-block-into-dwg-c/m-p/2006010#M77647</link>
      <description>how to insert existing block named "V1" into drawing?&lt;BR /&gt;
I'm bit under pressure and I'm not able to make from  samples mentioned on this forum.&lt;BR /&gt;
thanks in advance</description>
      <pubDate>Wed, 27 Jun 2007 20:41:06 GMT</pubDate>
      <guid>https://forums.autodesk.com/t5/net-forum/insert-existing-block-into-dwg-c/m-p/2006010#M77647</guid>
      <dc:creator>Anonymous</dc:creator>
      <dc:date>2007-06-27T20:41:06Z</dc:date>
    </item>
    <item>
      <title>Re: Insert existing block into DWG C#</title>
      <link>https://forums.autodesk.com/t5/net-forum/insert-existing-block-into-dwg-c/m-p/2006011#M77648</link>
      <description>So far I managed to make code below. But now I have no time to try it, could anybody fly though it and highlight probable mistakes?&lt;BR /&gt;
Thanks&lt;BR /&gt;
&lt;BR /&gt;
private acadDb.ObjectId CreateBlock(Autodesk.AutoCAD.Geometry.Point3d pos)&lt;BR /&gt;
    {&lt;BR /&gt;
      // get the current working database&lt;BR /&gt;
      acadDb.Database db = acadDb.HostApplicationServices.WorkingDatabase;&lt;BR /&gt;
      using (acadDb.Transaction trans = db.TransactionManager.StartTransaction())&lt;BR /&gt;
      {&lt;BR /&gt;
        acadDb.BlockTable bt = (acadDb.BlockTable)(trans.GetObject(db.BlockTableId, acadDb.OpenMode.ForWrite));&lt;BR /&gt;
        acadDb.BlockTableRecord btr = (acadDb.BlockTableRecord)trans.GetObject(bt["V1"], acadDb.OpenMode.ForWrite);&lt;BR /&gt;
        // Create the block reference...use the return from CreateEmployeeDefinition directly!&lt;BR /&gt;
        acadDb.BlockReference br = new acadDb.BlockReference(pos, btr.ObjectId);&lt;BR /&gt;
        // Add the reference to ModelSpace&lt;BR /&gt;
        btr.AppendEntity(br);&lt;BR /&gt;
        // Add the attribute reference to the block reference&lt;BR /&gt;
        trans.AddNewlyCreatedDBObject(br, true);&lt;BR /&gt;
        acadDb.ObjectId retId = br.ObjectId;&lt;BR /&gt;
        trans.Commit();&lt;BR /&gt;
        return retId;&lt;BR /&gt;
      }&lt;BR /&gt;
    }</description>
      <pubDate>Wed, 27 Jun 2007 20:58:47 GMT</pubDate>
      <guid>https://forums.autodesk.com/t5/net-forum/insert-existing-block-into-dwg-c/m-p/2006011#M77648</guid>
      <dc:creator>Anonymous</dc:creator>
      <dc:date>2007-06-27T20:58:47Z</dc:date>
    </item>
    <item>
      <title>Re: Insert existing block into DWG C#</title>
      <link>https://forums.autodesk.com/t5/net-forum/insert-existing-block-into-dwg-c/m-p/2006012#M77649</link>
      <description>What you have looks close enough, you *might need to alter it a bit, but the basis is correct.&lt;BR /&gt;
&lt;BR /&gt;
I would suggest: &lt;BR /&gt;
--Try to open bt with ForRead access. It may not require write access.&lt;BR /&gt;
--Use:  if(bt.Has("V1"))  as a "block exists" check.&lt;BR /&gt;
--Create the reference directly via: acadDb.BlockReference br = New acadDb.BlockReference(pos, bt["V1"])&lt;BR /&gt;
&lt;BR /&gt;
Of course, if the block doesn't exist you can load it from another drawing. Try working with the AcDb.Database methods: ReadDwgFile(), Insert() and WblockCloneObjects().</description>
      <pubDate>Wed, 27 Jun 2007 22:15:28 GMT</pubDate>
      <guid>https://forums.autodesk.com/t5/net-forum/insert-existing-block-into-dwg-c/m-p/2006012#M77649</guid>
      <dc:creator>jbooth</dc:creator>
      <dc:date>2007-06-27T22:15:28Z</dc:date>
    </item>
    <item>
      <title>Re: Insert existing block into DWG C#</title>
      <link>https://forums.autodesk.com/t5/net-forum/insert-existing-block-into-dwg-c/m-p/2006013#M77650</link>
      <description>There are posts here that show how to do&lt;BR /&gt;
that, which should give you the answers&lt;BR /&gt;
you need.&lt;BR /&gt;
&lt;BR /&gt;
-- &lt;BR /&gt;
http://www.caddzone.com&lt;BR /&gt;
&lt;BR /&gt;
AcadXTabs: MDI Document Tabs for AutoCAD 2008&lt;BR /&gt;
Supporting AutoCAD 2000 through 2008&lt;BR /&gt;
http://www.acadxtabs.com&lt;BR /&gt;
&lt;BR /&gt;
&lt;SUPEC&gt; wrote in message news:5640783@discussion.autodesk.com...&lt;BR /&gt;
how to insert existing block named "V1" into drawing?&lt;BR /&gt;
I'm bit under pressure and I'm not able to make from  samples mentioned on this forum.&lt;BR /&gt;
thanks in advance&lt;/SUPEC&gt;</description>
      <pubDate>Thu, 28 Jun 2007 00:44:59 GMT</pubDate>
      <guid>https://forums.autodesk.com/t5/net-forum/insert-existing-block-into-dwg-c/m-p/2006013#M77650</guid>
      <dc:creator>Anonymous</dc:creator>
      <dc:date>2007-06-28T00:44:59Z</dc:date>
    </item>
    <item>
      <title>Re: Insert existing block into DWG C#</title>
      <link>https://forums.autodesk.com/t5/net-forum/insert-existing-block-into-dwg-c/m-p/2006014#M77651</link>
      <description>Doesnt work:( no error message, no inserted block, I call this method with:&lt;BR /&gt;
CreateBlock(dataSet.Tables[0].Rows[intRadek]["sloupec"].ToString(), new Autodesk.AutoCAD.Geometry.Point3d(x, 0, 0));&lt;BR /&gt;
&lt;BR /&gt;
&lt;BR /&gt;
private acadDb.ObjectId CreateBlock(string nameOfBlock, Autodesk.AutoCAD.Geometry.Point3d pos)&lt;BR /&gt;
    {&lt;BR /&gt;
      // get the current working database&lt;BR /&gt;
      acadDb.Database db = acadDb.HostApplicationServices.WorkingDatabase;&lt;BR /&gt;
      using (acadDb.Transaction trans = db.TransactionManager.StartTransaction())&lt;BR /&gt;
      {&lt;BR /&gt;
        acadDb.BlockTable bt = (acadDb.BlockTable)(trans.GetObject(db.BlockTableId, acadDb.OpenMode.ForWrite));&lt;BR /&gt;
        acadDb.BlockTableRecord btr = (acadDb.BlockTableRecord)trans.GetObject(bt[nameOfBlock], acadDb.OpenMode.ForWrite);&lt;BR /&gt;
        // Create the block reference...use the return from CreateEmployeeDefinition directly!&lt;BR /&gt;
        //acadDb.BlockReference br = new acadDb.BlockReference(pos, bt[nameOfBlock]);&lt;BR /&gt;
        acadDb.BlockReference br = new acadDb.BlockReference(pos, btr.ObjectId);&lt;BR /&gt;
        // Add the reference to ModelSpace&lt;BR /&gt;
        btr.AppendEntity(br);&lt;BR /&gt;
        // Add the attribute reference to the block reference&lt;BR /&gt;
        trans.AddNewlyCreatedDBObject(br, true);&lt;BR /&gt;
        acadDb.ObjectId retId = br.ObjectId;&lt;BR /&gt;
        trans.Commit();&lt;BR /&gt;
        return retId;&lt;BR /&gt;
      }&lt;BR /&gt;
    }</description>
      <pubDate>Thu, 28 Jun 2007 06:45:08 GMT</pubDate>
      <guid>https://forums.autodesk.com/t5/net-forum/insert-existing-block-into-dwg-c/m-p/2006014#M77651</guid>
      <dc:creator>Anonymous</dc:creator>
      <dc:date>2007-06-28T06:45:08Z</dc:date>
    </item>
    <item>
      <title>Re: Insert existing block into DWG C#</title>
      <link>https://forums.autodesk.com/t5/net-forum/insert-existing-block-into-dwg-c/m-p/2006015#M77652</link>
      <description>It seems it works with:&lt;BR /&gt;
acadDb.BlockTableRecord btr = (acadDb.BlockTableRecord)trans.GetObject(bt[acadDb.BlockTableRecord.ModelSpace], acadDb.OpenMode.ForWrite);&lt;BR /&gt;
&lt;BR /&gt;
Thanks</description>
      <pubDate>Thu, 28 Jun 2007 07:01:27 GMT</pubDate>
      <guid>https://forums.autodesk.com/t5/net-forum/insert-existing-block-into-dwg-c/m-p/2006015#M77652</guid>
      <dc:creator>Anonymous</dc:creator>
      <dc:date>2007-06-28T07:01:27Z</dc:date>
    </item>
    <item>
      <title>Re: Insert existing block into DWG C#</title>
      <link>https://forums.autodesk.com/t5/net-forum/insert-existing-block-into-dwg-c/m-p/2006016#M77653</link>
      <description>Whole code, for future lames as I am:):&lt;BR /&gt;
&lt;BR /&gt;
private acadDb.ObjectId CreateBlock(string nameOfBlock, Autodesk.AutoCAD.Geometry.Point3d pos)&lt;BR /&gt;
    {&lt;BR /&gt;
      // get the current working database&lt;BR /&gt;
      acadDb.Database db = acadDb.HostApplicationServices.WorkingDatabase;&lt;BR /&gt;
      acadDb.Transaction trans = db.TransactionManager.StartTransaction();&lt;BR /&gt;
      acadDb.BlockTable bt = (acadDb.BlockTable)(trans.GetObject(db.BlockTableId, acadDb.OpenMode.ForRead));&lt;BR /&gt;
      acadDb.BlockTableRecord btr = (acadDb.BlockTableRecord)trans.GetObject(bt[acadDb.BlockTableRecord.ModelSpace], acadDb.OpenMode.ForWrite);&lt;BR /&gt;
      // Create the block reference...use the return from CreateEmployeeDefinition directly!&lt;BR /&gt;
      acadDb.BlockReference br = new acadDb.BlockReference(pos, bt[nameOfBlock]);&lt;BR /&gt;
      //acadDb.BlockReference br = new acadDb.BlockReference(pos, btr.ObjectId);&lt;BR /&gt;
      // Add the reference to ModelSpace&lt;BR /&gt;
      btr.AppendEntity(br);&lt;BR /&gt;
      // Add the attribute reference to the block reference&lt;BR /&gt;
      trans.AddNewlyCreatedDBObject(br, true);&lt;BR /&gt;
      acadDb.ObjectId retId = br.ObjectId;&lt;BR /&gt;
      //  trans.Commit();&lt;BR /&gt;
        &lt;BR /&gt;
      &lt;BR /&gt;
      trans.Commit();&lt;BR /&gt;
      trans.Dispose();&lt;BR /&gt;
      return retId;</description>
      <pubDate>Thu, 28 Jun 2007 07:16:20 GMT</pubDate>
      <guid>https://forums.autodesk.com/t5/net-forum/insert-existing-block-into-dwg-c/m-p/2006016#M77653</guid>
      <dc:creator>Anonymous</dc:creator>
      <dc:date>2007-06-28T07:16:20Z</dc:date>
    </item>
  </channel>
</rss>

