<?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: Repeatedly Insert Block in .NET Forum</title>
    <link>https://forums.autodesk.com/t5/net-forum/repeatedly-insert-block/m-p/3295855#M57604</link>
    <description>&lt;P&gt;For clarification, i can already insert a block, i essentially need to have an argument for my command in which i can specify a positive integer. So if i select the block i want to insert, it will ask me how for how many i would like to insert. I've got pretty much everything downpact except how to insert a block "x" amount of times over. I was thinking of two possible ways. 1.) This would involve just running the command i've posted "x" amount of times, but i'm unsure of the syntax or where to begin. 2.) Copy the block i've chosen to insert "x" amount of times -1. However, i'm still unsure of the syntax or where to begin. From a logic point of view i understand what i have to do, i've got a good amount of experience programming in a variety of languages however this AutoCAD API never ceases to confuse me. What you've posted below makes sense, but im looking more for a way to achieve what you've posted "x" amount of times.&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;Thanks!&lt;/P&gt;</description>
    <pubDate>Tue, 17 Jan 2012 16:35:24 GMT</pubDate>
    <dc:creator>Anonymous</dc:creator>
    <dc:date>2012-01-17T16:35:24Z</dc:date>
    <item>
      <title>Repeatedly Insert Block</title>
      <link>https://forums.autodesk.com/t5/net-forum/repeatedly-insert-block/m-p/3295575#M57602</link>
      <description>&lt;P&gt;Hey everyone,&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;So i've been able to successfully import a single block at a time into an active drawing, now i'm trying to insert the same block multiple times to essentially create a layout within the drawing. How would i go about inserting a selected block "x" amount of times. For a better idea of where i'm stuck, i've commented a bit of code below with a better explanation. &amp;nbsp;What i've got so far is this:&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;using System;&lt;BR /&gt;using System.Collections.Generic;&lt;BR /&gt;using System.ComponentModel;&lt;BR /&gt;using System.Data;&lt;BR /&gt;using System.Drawing;&lt;BR /&gt;using System.Linq;&lt;BR /&gt;using System.Text;&lt;BR /&gt;using System.Windows.Forms;&lt;BR /&gt;using Autodesk.AutoCAD.Runtime;&lt;BR /&gt;using Autodesk.AutoCAD.ApplicationServices;&lt;BR /&gt;using Autodesk.AutoCAD.DatabaseServices;&lt;BR /&gt;using Autodesk.AutoCAD.Geometry;&lt;BR /&gt;using Autodesk.AutoCAD.EditorInput;&lt;BR /&gt;using Autodesk.AutoCAD.DataExtraction;&lt;BR /&gt;using Autodesk.AutoCAD.Colors;&lt;BR /&gt;using DB_Extraction;&lt;BR /&gt;using acadApp = Autodesk.AutoCAD.ApplicationServices.Application;&lt;/P&gt;&lt;P&gt;namespace CHTEST&lt;BR /&gt;{&lt;BR /&gt;public class CHTEST1&lt;BR /&gt;{&lt;BR /&gt;// This is the name of my command&lt;/P&gt;&lt;P&gt;[Autodesk.AutoCAD.Runtime.CommandMethod("CHTEST")]&lt;/P&gt;&lt;P&gt;public void CHTEST1()&lt;BR /&gt;{&lt;BR /&gt;{&lt;BR /&gt;&lt;BR /&gt;Document doc = Autodesk.AutoCAD.ApplicationServices.Application.DocumentManager.MdiActiveDocument;&lt;BR /&gt;Database db = doc.Database;&lt;BR /&gt;Editor ed = doc.Editor;&lt;BR /&gt;Point3d pMax = new Point3d();&lt;BR /&gt;string comp = "C:\\ACADSTUFF\\test.dwg";&lt;BR /&gt;// int numsprink = 5;&lt;/P&gt;&lt;P&gt;Transaction tr = doc.TransactionManager.StartTransaction();&lt;BR /&gt;using (DocumentLock acLckDoc = doc.LockDocument())&lt;/P&gt;&lt;P&gt;try&lt;BR /&gt;{&lt;/P&gt;&lt;P&gt;//Check to see if the layer CH-TST already exists, if so use it, if not create it and then use it&lt;BR /&gt;string sLayerName1 = "CH-TST";&lt;/P&gt;&lt;P&gt;LayerTable acLyrTbl1; acLyrTbl1 = tr.GetObject(db.LayerTableId, OpenMode.ForRead) as LayerTable;&lt;BR /&gt;LayerTableRecord acLyrTblRec;&lt;/P&gt;&lt;P&gt;if (acLyrTbl1.Has(sLayerName1) == false)&lt;BR /&gt;{&lt;BR /&gt;acLyrTblRec = new LayerTableRecord();&lt;BR /&gt;// Assign the layer a name&lt;BR /&gt;acLyrTblRec.Name = sLayerName1;&lt;/P&gt;&lt;P&gt;// Upgrade the Layer table for write&lt;BR /&gt;if (acLyrTbl1.IsWriteEnabled == false) acLyrTbl1.UpgradeOpen();&lt;/P&gt;&lt;P&gt;// Append the new layer to the Layer table and the transaction&lt;BR /&gt;acLyrTbl1.Add(acLyrTblRec);&lt;BR /&gt;tr.AddNewlyCreatedDBObject(acLyrTblRec, true);&lt;BR /&gt;}&lt;BR /&gt;else&lt;BR /&gt;{&lt;BR /&gt;// Open the layer if it already exists for write&lt;BR /&gt;acLyrTblRec = tr.GetObject(acLyrTbl1[sLayerName1], OpenMode.ForWrite) as LayerTableRecord;&lt;/P&gt;&lt;P&gt;}&lt;/P&gt;&lt;P&gt;&lt;BR /&gt;//This partwill import the selected dwg into modelspace and activate it&lt;BR /&gt;string dwgName = HostApplicationServices.Current.FindFile(comp, acadApp.DocumentManager.MdiActiveDocument.Database, FindFileHint.Default);&lt;/P&gt;&lt;P&gt;Database db1 = new Database(false, false);&lt;/P&gt;&lt;P&gt;db1.ReadDwgFile(dwgName, System.IO.FileShare.Read, true, "");&lt;/P&gt;&lt;P&gt;ObjectId BlkId;&lt;/P&gt;&lt;P&gt;BlkId = doc.Database.Insert(dwgName, db1, false);&lt;/P&gt;&lt;P&gt;BlockTable bt = (BlockTable)tr.GetObject(doc.Database.BlockTableId, OpenMode.ForRead, true);&lt;/P&gt;&lt;P&gt;BlockTableRecord btr = (BlockTableRecord)tr.GetObject(bt[BlockTableRecord.ModelSpace], OpenMode.ForWrite);&lt;/P&gt;&lt;P&gt;&lt;BR /&gt;//ideally this next section will iterate the import process "x" amount of times and allow for effetive block placement!&lt;BR /&gt;&lt;BR /&gt;// Below is part of some code that i had used to copy a paperspace layout "x" amount of times. I understand the iteration part but am not sure how to apply it to a block. I don't know how to reference the block that i intend to insert and then have it populate "x" amount of times.&lt;BR /&gt;/*&lt;BR /&gt;for (int i = 1; i &amp;lt;= numLayouts; i++)&lt;BR /&gt;{&lt;BR /&gt;lm.CopyLayout("Layout1", "SP-" + i.ToString());&lt;BR /&gt;Layout layout = (Layout)trx.GetObject(lm.GetLayoutId("SP-" + i.ToString()), OpenMode.ForWrite);&lt;/P&gt;&lt;P&gt;}&lt;BR /&gt;&lt;BR /&gt;*/&lt;/P&gt;&lt;P&gt;&lt;BR /&gt;//FACSPR7&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;BlockReference bref = new BlockReference(pMax, BlkId);&lt;/P&gt;&lt;P&gt;bref.Layer = "CH-TST";&lt;/P&gt;&lt;P&gt;btr.AppendEntity(bref);&lt;/P&gt;&lt;P&gt;tr.AddNewlyCreatedDBObject(bref, true);&lt;/P&gt;&lt;P&gt;bref.ExplodeToOwnerSpace();&lt;/P&gt;&lt;P&gt;bref.Erase();&lt;/P&gt;&lt;P&gt;tr.Commit();&lt;/P&gt;&lt;P&gt;&lt;BR /&gt;}&lt;BR /&gt;catch&lt;BR /&gt;{&lt;BR /&gt;MessageBox.Show("Failed to read the DWG from the refence folder, are you sure it is present?");&lt;BR /&gt;}&lt;BR /&gt;finally&lt;BR /&gt;{&lt;BR /&gt;tr.Dispose();&lt;BR /&gt;}&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&lt;BR /&gt;}&lt;/P&gt;&lt;P&gt;}&lt;BR /&gt;}&lt;/P&gt;&lt;P&gt;}&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Tue, 17 Jan 2012 14:06:12 GMT</pubDate>
      <guid>https://forums.autodesk.com/t5/net-forum/repeatedly-insert-block/m-p/3295575#M57602</guid>
      <dc:creator>Anonymous</dc:creator>
      <dc:date>2012-01-17T14:06:12Z</dc:date>
    </item>
    <item>
      <title>Re: Repeatedly Insert Block</title>
      <link>https://forums.autodesk.com/t5/net-forum/repeatedly-insert-block/m-p/3295779#M57603</link>
      <description>&lt;P&gt;Can you clarify a bit? I'll give it a try. But maybe I'm missing your point.&amp;nbsp;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;You could just use the same command basically &lt;EM&gt;block insert&lt;/EM&gt; several times and them DB commit when you're done.&amp;nbsp;&lt;/P&gt;&lt;P&gt;Or just create several instances of a blockreference. Or you can use the copy object command.&amp;nbsp;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;Instead of Insert MText entity like in the code below insert a BlockReference Entity&lt;/P&gt;&lt;P&gt;(&amp;nbsp;Dim myBRef As BlockReference)&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;I got this code from:&lt;/P&gt;&lt;P&gt;AutoCAD® .NET Basics, Part I&lt;BR /&gt;Stephen Preston – Autodesk Inc&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;Hope you don't mind I'm using VB.NET&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;PRE&gt;Imports Autodesk.AutoCAD.Runtime
Imports Autodesk.AutoCAD.ApplicationServices
Imports Autodesk.AutoCAD.DatabaseServices

    Public Class Class1
        &amp;lt;CommandMethod("HelloWorld")&amp;gt; _
        Public Sub MyMethod()
            ' Some variable definitions
            Dim DB As Database
            Dim BT As BlockTable
            Dim MS As BlockTableRecord
            ' Start a transaction to edit the DWG database
            Using trans As Transaction = Application.DocumentManager.MdiActiveDocument.TransactionManager.StartT()
                ransaction()
                ' Open ModelSpace BlockTableRecord ready to add entity
                DB = Application.DocumentManager.MdiActiveDocument.Database
                BT = trans.GetObject(DB.BlockTableId, OpenMode.ForRead)
                MS = trans.GetObject(BT(BlockTableRecord.ModelSpace), OpenMode.ForWrite)

                ' Create a new MText entity and set its text
                Dim txt As MText = New MText
                txt.Contents = "Hello World from VB.NET"&lt;BR /&gt;
                ' Add the MText to ModelSpace
                MS.AppendEntity(txt)&lt;BR /&gt;
                ' Add the Mtext to the transaction
                trans.AddNewlyCreatedDBObject(txt, True)&lt;BR /&gt;
                ' Commit transaction so changes persist in the DWG
                trans.Commit()
            End Using
        End Sub
    End Class&lt;/PRE&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;/P&gt;</description>
      <pubDate>Tue, 17 Jan 2012 16:12:12 GMT</pubDate>
      <guid>https://forums.autodesk.com/t5/net-forum/repeatedly-insert-block/m-p/3295779#M57603</guid>
      <dc:creator>Anonymous</dc:creator>
      <dc:date>2012-01-17T16:12:12Z</dc:date>
    </item>
    <item>
      <title>Re: Repeatedly Insert Block</title>
      <link>https://forums.autodesk.com/t5/net-forum/repeatedly-insert-block/m-p/3295855#M57604</link>
      <description>&lt;P&gt;For clarification, i can already insert a block, i essentially need to have an argument for my command in which i can specify a positive integer. So if i select the block i want to insert, it will ask me how for how many i would like to insert. I've got pretty much everything downpact except how to insert a block "x" amount of times over. I was thinking of two possible ways. 1.) This would involve just running the command i've posted "x" amount of times, but i'm unsure of the syntax or where to begin. 2.) Copy the block i've chosen to insert "x" amount of times -1. However, i'm still unsure of the syntax or where to begin. From a logic point of view i understand what i have to do, i've got a good amount of experience programming in a variety of languages however this AutoCAD API never ceases to confuse me. What you've posted below makes sense, but im looking more for a way to achieve what you've posted "x" amount of times.&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;Thanks!&lt;/P&gt;</description>
      <pubDate>Tue, 17 Jan 2012 16:35:24 GMT</pubDate>
      <guid>https://forums.autodesk.com/t5/net-forum/repeatedly-insert-block/m-p/3295855#M57604</guid>
      <dc:creator>Anonymous</dc:creator>
      <dc:date>2012-01-17T16:35:24Z</dc:date>
    </item>
    <item>
      <title>Re: Repeatedly Insert Block</title>
      <link>https://forums.autodesk.com/t5/net-forum/repeatedly-insert-block/m-p/3299877#M57605</link>
      <description>&lt;P&gt;vince1327 can you tell me ; do you want to insert a block definition x number of times or do you want to create a blockreference of a block definition you have x number of times. maybe i got you wrong but just to be clear :&lt;/P&gt;&lt;P&gt;- do we aggree that a block definition is a blocktablerecord in blocktable symbol table that has entities in it?&lt;/P&gt;&lt;P&gt;- do we aggree that a blockreference is a like an entity that references a blocktablerecord.&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;i mean the block definition is the blueprint while the blockreference is the actual objects in the drawing.&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;as i said before maybe i got you wrong (if so please discard this post) but you want to insert objects to the drawing. so instead of inserting blocktablerecord s xnumber of times try to insert blockreferences of that blocktablerecord x number of times.&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;if that is what you mean please confirm for code example.&lt;/P&gt;</description>
      <pubDate>Thu, 19 Jan 2012 20:29:51 GMT</pubDate>
      <guid>https://forums.autodesk.com/t5/net-forum/repeatedly-insert-block/m-p/3299877#M57605</guid>
      <dc:creator>cincir</dc:creator>
      <dc:date>2012-01-19T20:29:51Z</dc:date>
    </item>
    <item>
      <title>Re: Repeatedly Insert Block</title>
      <link>https://forums.autodesk.com/t5/net-forum/repeatedly-insert-block/m-p/3299919#M57606</link>
      <description>&lt;P&gt;Hi Cincir,&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;I'm new to AutoCAD overall and i've just spoken with one of our designers who has indeed confirmed what you've said. I'm looking to insert blockreferences of my block "x" number of times. The AutoCAD API is tricky to learn and is sometimes a bit confusing so i appreciate your time trying to help me find what i'm looking for. If you have an example of how to do this, it would be amazing!&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;</description>
      <pubDate>Thu, 19 Jan 2012 20:58:07 GMT</pubDate>
      <guid>https://forums.autodesk.com/t5/net-forum/repeatedly-insert-block/m-p/3299919#M57606</guid>
      <dc:creator>Anonymous</dc:creator>
      <dc:date>2012-01-19T20:58:07Z</dc:date>
    </item>
    <item>
      <title>Re: Repeatedly Insert Block</title>
      <link>https://forums.autodesk.com/t5/net-forum/repeatedly-insert-block/m-p/3299977#M57607</link>
      <description>&lt;P&gt;[CommandMethod("CreateBlockReference")]&lt;/P&gt;&lt;P&gt;public void CreateBlockReference()&lt;/P&gt;&lt;P&gt;{&lt;/P&gt;&lt;P&gt;Document acDoc = Application.DocumentManager.MdiActiveDocument;&lt;/P&gt;&lt;P&gt;Editor acEd = acDoc.Editor;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&lt;SPAN style="white-space: pre;"&gt;P&lt;/SPAN&gt;romptStringOptions acPSO = new PromptStringOptions("Enter the name of block you want to insert:");&lt;/P&gt;&lt;P&gt;PromptResult acPR = acEd.GetString(acPSO);&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;if (acPR.Status == PromptStatus.OK)&lt;/P&gt;&lt;P&gt;{&lt;/P&gt;&lt;P&gt;using (Transaction acTrans = acDoc.TransactionManager.StartTransaction())&lt;/P&gt;&lt;P&gt;{&lt;/P&gt;&lt;P&gt;BlockTable acBlkTbl = acTrans.GetObject(acDoc.Database.BlockTableId, OpenMode.ForRead) as BlockTable;&lt;/P&gt;&lt;P&gt;if (acBlkTbl.Has(acPR.StringResult) == true) // Our BlockTable has block definition that we enter&lt;/P&gt;&lt;P&gt;{&lt;/P&gt;&lt;P&gt;ObjectId acBlockId = acTrans.GetObject(acBlkTbl[acPR.StringResult],OpenMode.ForRead);&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;PromptIntegerOptions acPIO = new PromptInterOptions("Enter the number of times block will be inserted:");&lt;/P&gt;&lt;P&gt;acPIO.AllowNegative = false;&lt;/P&gt;&lt;P&gt;acPIO.AllowZero = false;&lt;/P&gt;&lt;P&gt;PromptIntegerResult acPIR = acEd.GetInteger(acPIO);&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;if (acPIR.Status == PromptStatus.OK)&lt;/P&gt;&lt;P&gt;{&lt;/P&gt;&lt;P&gt;BlockTableRecord acBlkTblRec = acTrans.GetObject(BlockTableRecord.ModelSpace,OpenMode.ForWrite) as BlockTableRecord;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;Point3d pCenter = new Point3d(0,0,0);&lt;/P&gt;&lt;P&gt;Vector3d vOffset = new Vector3d(10,0,0);&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&lt;SPAN style="white-space: pre;"&gt;f&lt;/SPAN&gt;or (int i = 0;i &amp;lt; acPIR.Value ; i++)&lt;/P&gt;&lt;P&gt;{&lt;/P&gt;&lt;P&gt;BlockReference acBR = new BlockReference(pCenter , acBlockId);&lt;/P&gt;&lt;P&gt;acBlkTblRec.AppendEntity(acBR);&lt;/P&gt;&lt;P&gt;acTrans.AddNewlyCreatedObject(acBR,true);&lt;/P&gt;&lt;P&gt;pCenter += vOffset;&lt;/P&gt;&lt;P&gt;}&lt;/P&gt;&lt;P&gt;}&lt;/P&gt;&lt;P&gt;}&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&lt;SPAN style="white-space: pre;"&gt;a&lt;/SPAN&gt;cTrans.Commit();&lt;/P&gt;&lt;P&gt;}&lt;/P&gt;&lt;P&gt;}&lt;/P&gt;&lt;P&gt;}&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;i just wrote it i mean didnt copy-paste so may have syntax errors. feel free to ask questions for this or other stuff.&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;good luck.&lt;/P&gt;</description>
      <pubDate>Thu, 19 Jan 2012 21:41:51 GMT</pubDate>
      <guid>https://forums.autodesk.com/t5/net-forum/repeatedly-insert-block/m-p/3299977#M57607</guid>
      <dc:creator>cincir</dc:creator>
      <dc:date>2012-01-19T21:41:51Z</dc:date>
    </item>
    <item>
      <title>Re: Repeatedly Insert Block</title>
      <link>https://forums.autodesk.com/t5/net-forum/repeatedly-insert-block/m-p/3300887#M57608</link>
      <description>&lt;P&gt;Like Cincir said:&amp;nbsp;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;For each Block Reference use&amp;nbsp;&lt;/P&gt;&lt;P&gt;.AppendEntity&amp;nbsp;&lt;/P&gt;&lt;P&gt;.AddNewlyCreatedObject&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;Those are your guys.&amp;nbsp;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;It's sure good to hear I'm not the only one who thinks the Autocad API is confusing.&amp;nbsp;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Fri, 20 Jan 2012 15:28:57 GMT</pubDate>
      <guid>https://forums.autodesk.com/t5/net-forum/repeatedly-insert-block/m-p/3300887#M57608</guid>
      <dc:creator>Anonymous</dc:creator>
      <dc:date>2012-01-20T15:28:57Z</dc:date>
    </item>
    <item>
      <title>Re: Repeatedly Insert Block</title>
      <link>https://forums.autodesk.com/t5/net-forum/repeatedly-insert-block/m-p/3303367#M57609</link>
      <description>&lt;P&gt;Thanks for the help so far! I'm just stuck on one line below. I get this error in VS 2010 "&lt;/P&gt;&lt;P&gt;Error 1 Cannot implicitly convert type 'Autodesk.AutoCAD.DatabaseServices.BlockTable' to 'Autodesk.AutoCAD.DatabaseServices.ObjectId'" How do i re-arrange this to work?&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;&amp;nbsp;&lt;/P&gt;&lt;P&gt;namespace TEST&lt;BR /&gt;{&lt;BR /&gt;public class TEST&lt;BR /&gt;{&lt;BR /&gt;// This is the name of my command&lt;/P&gt;&lt;P&gt;[Autodesk.AutoCAD.Runtime.CommandMethod("CHTEST")]&lt;/P&gt;&lt;P&gt;public void TEST()&lt;BR /&gt;{&lt;BR /&gt;Document acDoc = Autodesk.AutoCAD.ApplicationServices.Application.DocumentManager.MdiActiveDocument;&lt;BR /&gt;Editor acEd = acDoc.Editor;&lt;BR /&gt;string comp = "C:\\ACADSTUFF\\test.dwg";&lt;/P&gt;&lt;P&gt;PromptStringOptions acPSO = new PromptStringOptions("Enter the name of block you want to insert:");&lt;BR /&gt;PromptResult acPR = acEd.GetString(acPSO);&lt;/P&gt;&lt;P&gt;if (acPR.Status == PromptStatus.OK)&lt;BR /&gt;{&lt;BR /&gt;using (Transaction acTrans = acDoc.TransactionManager.StartTransaction())&lt;BR /&gt;{&lt;BR /&gt;BlockTable acBlkTbl = acTrans.GetObject(acDoc.Database.BlockTableId, OpenMode.ForRead) as BlockTable;&lt;BR /&gt;if (acBlkTbl.Has(acPR.StringResult) == true) // Our BlockTable has block definition that we enter&lt;BR /&gt;{&lt;BR /&gt;&lt;BR /&gt;&lt;U&gt;&lt;STRONG&gt;ObjectId acBlockId = (BlockTable)acTrans.GetObject(acBlkTbl[acPR.StringResult], OpenMode.ForRead);&lt;/STRONG&gt;&lt;/U&gt;&lt;/P&gt;&lt;P&gt;&lt;BR /&gt;//ObjectId acBlockId = (BlockTableRecord)acTrans.GetObject(btr[acPR.StringResult], OpenMode.ForWrite);&lt;BR /&gt;//ObjectId acBlockId = acTrans.GetObject(acBlkTbl[acPR.StringResult],OpenMode.ForRead);&lt;/P&gt;&lt;P&gt;PromptIntegerOptions acPIO = new PromptIntegerOptions("Enter the number of times block will be inserted:");&lt;BR /&gt;acPIO.AllowNegative = false;&lt;BR /&gt;acPIO.AllowZero = false;&lt;BR /&gt;PromptIntegerResult acPIR = acEd.GetInteger(acPIO);&lt;/P&gt;&lt;P&gt;if (acPIR.Status == PromptStatus.OK)&lt;BR /&gt;{&lt;/P&gt;&lt;P&gt;BlockTable bt = (BlockTable)acTrans.GetObject(acDoc.Database.BlockTableId, OpenMode.ForRead, true);&lt;BR /&gt;BlockTableRecord acBlkTblRec = (BlockTableRecord)acTrans.GetObject(bt[BlockTableRecord.ModelSpace], OpenMode.ForWrite);&lt;/P&gt;&lt;P&gt;Point3d pCenter = new Point3d(0, 0, 0);&lt;BR /&gt;Vector3d vOffset = new Vector3d(10, 0, 0);&lt;/P&gt;&lt;P&gt;for (int i = 0; i &amp;lt; acPIR.Value; i++)&lt;BR /&gt;{&lt;BR /&gt;BlockReference acBR = new BlockReference(pCenter, acBlockId);&lt;BR /&gt;acBlkTblRec.AppendEntity(acBR);&lt;BR /&gt;acTrans.AddNewlyCreatedDBObject(acBR, true);&lt;BR /&gt;pCenter += vOffset;&lt;BR /&gt;}&lt;BR /&gt;}&lt;BR /&gt;}&lt;/P&gt;&lt;P&gt;acTrans.Commit();&lt;BR /&gt;}&lt;BR /&gt;}&lt;BR /&gt;}&lt;BR /&gt;}&lt;BR /&gt;&lt;BR /&gt;}&lt;/P&gt;</description>
      <pubDate>Mon, 23 Jan 2012 20:06:07 GMT</pubDate>
      <guid>https://forums.autodesk.com/t5/net-forum/repeatedly-insert-block/m-p/3303367#M57609</guid>
      <dc:creator>Anonymous</dc:creator>
      <dc:date>2012-01-23T20:06:07Z</dc:date>
    </item>
    <item>
      <title>Re: Repeatedly Insert Block</title>
      <link>https://forums.autodesk.com/t5/net-forum/repeatedly-insert-block/m-p/3303517#M57610</link>
      <description>&lt;P&gt;Hmm....&amp;nbsp;&lt;/P&gt;&lt;P&gt;&lt;U&gt;&lt;STRONG&gt;ObjectId acBlockId = (BlockTable)acTrans.GetObject(acBlkTbl[acPR.StringResult], OpenMode.ForRead);&lt;/STRONG&gt;&lt;/U&gt;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;Why don't you skip that last line of code?&amp;nbsp;&lt;/P&gt;&lt;P&gt;Just use:&amp;nbsp;BlockReference acBR = new BlockReference(pCenter, &lt;STRONG&gt;myBlockTable(BlockName)&lt;/STRONG&gt;);&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;That way you don't have to worry about the object conflict your coming across.&amp;nbsp;&lt;/P&gt;&lt;P&gt;And as long as a block with that name exists your fine.&amp;nbsp;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;Okay so maybe this doesn't help at all. But I figure at least try to excercise my programming brain muscle to make it stronger &lt;span class="lia-unicode-emoji" title=":slightly_smiling_face:"&gt;🙂&lt;/span&gt;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;Good Luck!&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;Maybe this will help:&lt;/P&gt;&lt;PRE&gt;Public Function ModelSpaceInsertBlock(ByVal InsPt As Geometry.Point3d, _
	ByVal BlockName As String, ByVal XScale As Double, _
	ByVal YScale As Double, ByVal ZScale As Double) As DatabaseServices.ObjectId
		Dim myBlkID As ObjectId = ObjectId.Null
		Try

			Dim myDwg As Document = Application.DocumentManager.MdiActiveDocument
			Using myTrans As Transaction = myDwg.TransactionManager.StartTransaction

				'Open the database for Write
				Dim myBT As BlockTable = myDwg.Database.BlockTableId.GetObject(OpenMode.ForRead)
				Dim myModelSpace As BlockTableRecord = myBT(BlockTableRecord.ModelSpace).GetObject(OpenMode.ForWrite)

				'Insert the Block
				Dim myBlockDef As BlockTableRecord = myBT(BlockName).GetObject(OpenMode.ForRead)
				Dim myBlockRef As New DatabaseServices.BlockReference(InsPt, myBT(BlockName))
				myBlockRef.ScaleFactors = New Geometry.Scale3d(XScale, YScale, ZScale)

				myModelSpace.AppendEntity(myBlockRef)
				myTrans.AddNewlyCreatedDBObject(myBlockRef, True)
				myBlkID = myBlockRef.ObjectId

				'Append Attribute References to the BlockReference
				Dim myAttColl As DatabaseServices.AttributeCollection
				Dim myEntID As ObjectId
				Dim myEnt As DatabaseServices.Entity
				myAttColl = myBlockRef.AttributeCollection
				For Each myEntID In myBlockDef
					myEnt = myEntID.GetObject(OpenMode.ForWrite)
					If TypeOf myEnt Is DatabaseServices.AttributeDefinition Then
						Dim myAttDef As DatabaseServices.AttributeDefinition = CType(myEnt, AttributeDefinition)
						Dim myAttRef As New DatabaseServices.AttributeReference
						myAttRef.SetAttributeFromBlock(myAttDef, myBlockRef.BlockTransform)
						myAttColl.AppendAttribute(myAttRef)
						myTrans.AddNewlyCreatedDBObject(myAttRef, True)
					End If
				Next

				'Commit the Transaction
				myTrans.Commit()
			End Using
		Catch ex As Exception
			myBlkID = ObjectId.Null
		End Try

		Return myBlkID
	End Function&lt;/PRE&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;I also found this snippet in C#&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;PRE&gt;using Autodesk.AutoCAD.ApplicationServices;
using Autodesk.AutoCAD.DatabaseServices;
using Autodesk.AutoCAD.EditorInput;
using Autodesk.AutoCAD.Geometry;
using Autodesk.AutoCAD.Runtime;

namespace BlockInsertion
{
    public class Class1
    {
        [CommandMethod("Test")]
        public void Test()
        {
            Document doc = Application.DocumentManager.MdiActiveDocument;
            Database db = doc.Database;
            Editor ed = doc.Editor;

            // Get the block name
            PromptStringOptions pso = new PromptStringOptions("\nEnter block name: ");
            PromptResult pr = ed.GetString(pso);
            if (pr.Status == PromptStatus.OK)
            {
                // Start a transaction
                using (Transaction tr = db.TransactionManager.StartTransaction())
                {
                    // Test if block exists in the block table
                    BlockTable bt = (BlockTable)tr.GetObject(db.BlockTableId, OpenMode.ForRead);
                    if (!bt.Has(pr.StringResult))
                    {
                        ed.WriteMessage("\nBlock not found.");
                    }
                    else
                    {
                        ObjectId id = bt[pr.StringResult];

                        // Get insertion point
                        PromptPointOptions ppo = new PromptPointOptions("\nSpecify insertion point: ");
                        PromptPointResult ppr = ed.GetPoint(ppo);
                        if (ppr.Status == PromptStatus.OK)
                        {
                            Point3d pt = ppr.Value.TransformBy(ed.CurrentUserCoordinateSystem);

                            // Create a block reference
                            BlockReference br = new BlockReference(pt, id);

                            // Get Model space
                            BlockTableRecord btr = (BlockTableRecord)tr.GetObject(bt[BlockTableRecord.ModelSpace], OpenMode.ForWrite);

                            // Add the block reference to Model space
                            btr.AppendEntity(br);
                            tr.AddNewlyCreatedDBObject(br, true);
                        }
                    }

                    // Commit the transaction
                    tr.Commit();
                }
            }
        }
    }
}&lt;/PRE&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Mon, 23 Jan 2012 21:17:25 GMT</pubDate>
      <guid>https://forums.autodesk.com/t5/net-forum/repeatedly-insert-block/m-p/3303517#M57610</guid>
      <dc:creator>Anonymous</dc:creator>
      <dc:date>2012-01-23T21:17:25Z</dc:date>
    </item>
    <item>
      <title>Re: Repeatedly Insert Block</title>
      <link>https://forums.autodesk.com/t5/net-forum/repeatedly-insert-block/m-p/3303703#M57611</link>
      <description>&lt;P&gt;&lt;SPAN&gt;ObjectId acBlockId = acTrans.GetObject(acBlkTbl[acPR.StringResult],Open&lt;/SPAN&gt;&lt;SPAN&gt;Mode.ForRead); &lt;/SPAN&gt;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&lt;SPAN&gt;change this line to&lt;/SPAN&gt;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&lt;SPAN&gt;&lt;SPAN&gt;ObjectId acBlockId = acBlkTbl[acPR.StringResult]&lt;/SPAN&gt;&lt;SPAN&gt;;&lt;/SPAN&gt;&lt;/SPAN&gt;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&lt;SPAN&gt;&lt;SPAN&gt;as i said before i just typed it not copy - paste.&amp;nbsp;&lt;/SPAN&gt;&lt;/SPAN&gt;&lt;/P&gt;</description>
      <pubDate>Mon, 23 Jan 2012 23:35:55 GMT</pubDate>
      <guid>https://forums.autodesk.com/t5/net-forum/repeatedly-insert-block/m-p/3303703#M57611</guid>
      <dc:creator>cincir</dc:creator>
      <dc:date>2012-01-23T23:35:55Z</dc:date>
    </item>
    <item>
      <title>Re: Repeatedly Insert Block</title>
      <link>https://forums.autodesk.com/t5/net-forum/repeatedly-insert-block/m-p/3305019#M57612</link>
      <description>&lt;P&gt;Thanks a million, i've got it up and running so far, I really do appreciate everyone's help. I have just one last question that may be a bit unrealted, however here goes. When I create my new block reference and append it, it imports on the layer it was on in it's original DWG. How do i specify it to import onto a layer of my choosing. I've tried this already:&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;for (int i = 0; i &amp;lt; quantity; i++)&lt;BR /&gt;{&lt;BR /&gt;&lt;BR /&gt;BlockReference bref = new BlockReference(pCenter, BlkId);&lt;/P&gt;&lt;P&gt;&lt;STRONG&gt;&lt;EM&gt;&lt;U&gt;bref.Layer = "CH-SPR";&lt;/U&gt;&lt;/EM&gt;&lt;/STRONG&gt;&lt;/P&gt;&lt;P&gt;btr.AppendEntity(bref);&lt;/P&gt;&lt;P&gt;tr.AddNewlyCreatedDBObject(bref, true);&lt;/P&gt;&lt;P&gt;pCenter += vOffset;&lt;/P&gt;&lt;P&gt;bref.ExplodeToOwnerSpace();&lt;/P&gt;&lt;P&gt;bref.Erase();&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;}&lt;BR /&gt;&lt;BR /&gt;}&lt;BR /&gt;catch&lt;BR /&gt;{&lt;BR /&gt;MessageBox.Show("Failed to read the DWG from the refence folder, are you sure it is present?");&lt;BR /&gt;}&lt;BR /&gt;finally&lt;BR /&gt;{&lt;BR /&gt;tr.Commit();&lt;BR /&gt;this.Close();&lt;BR /&gt;}&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;Thanks again&lt;/P&gt;&lt;P&gt;Vince&lt;/P&gt;</description>
      <pubDate>Tue, 24 Jan 2012 21:24:53 GMT</pubDate>
      <guid>https://forums.autodesk.com/t5/net-forum/repeatedly-insert-block/m-p/3305019#M57612</guid>
      <dc:creator>Anonymous</dc:creator>
      <dc:date>2012-01-24T21:24:53Z</dc:date>
    </item>
    <item>
      <title>Re: Repeatedly Insert Block</title>
      <link>https://forums.autodesk.com/t5/net-forum/repeatedly-insert-block/m-p/3305079#M57613</link>
      <description>&lt;P&gt;what is wrong with your code. it will work if there is a layer named like that. bu you have to set the attributereferences' layer to that only if they exist.if you want to assign LayerId property of the object you must first get your layertablerecord first like this&amp;nbsp;&lt;/P&gt;&lt;PRE&gt;LayerTable acLayerTbl = acTrans.GetObject(acCurDB.LayerTableId,OpenMode.ForRead) as LayerTable;

ObjectId acLayerId = ObjectId.Null;
if (acLayerTbl.Has("SomeLayerName"))
{
    acLayerId = acLayerTbl["SomeLayerName"];
}
else
{
    LayerTableRecord acLayerTblRec = new LayerTableRecord();
    acLayerTblRec.Name = "SomeLayerName";
    acLayerTbl.UpgradeOpen();
    acLayerId = acLayerTbl.Add(acLyerTblRec);
    acTrans.AddNewlyCreatedObject(acLayerTblRec,true);
}

acBlkRef.LayerId = acLayerId;

&lt;/PRE&gt;&lt;P&gt;&amp;nbsp;use this aproach if you want to check if there is the layer you want to assign and create if not.&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Tue, 24 Jan 2012 21:57:08 GMT</pubDate>
      <guid>https://forums.autodesk.com/t5/net-forum/repeatedly-insert-block/m-p/3305079#M57613</guid>
      <dc:creator>cincir</dc:creator>
      <dc:date>2012-01-24T21:57:08Z</dc:date>
    </item>
    <item>
      <title>Re: Repeatedly Insert Block</title>
      <link>https://forums.autodesk.com/t5/net-forum/repeatedly-insert-block/m-p/3305767#M57614</link>
      <description>&lt;P&gt;Hey Cincir,&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;I've actually create the layer beforehand and can verify that it exists...the code looks like below. I'm not sure why it won't import onto the CH-SPR layer though, this has been one of those small things on my list for weeks now and it's driving me mad.&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;Transaction tr = doc.TransactionManager.StartTransaction();&lt;BR /&gt;using (DocumentLock acLckDoc = doc.LockDocument())&lt;/P&gt;&lt;P&gt;try&lt;BR /&gt;{&lt;/P&gt;&lt;P&gt;//Check to see if the layer CH-SPR already exists, if so use it, if not create it and then use it&lt;BR /&gt;string sLayerName1 = "CH-SPR";&lt;/P&gt;&lt;P&gt;LayerTable acLyrTbl1; acLyrTbl1 = tr.GetObject(db.LayerTableId, OpenMode.ForRead) as LayerTable;&lt;BR /&gt;LayerTableRecord acLyrTblRec;&lt;/P&gt;&lt;P&gt;if (acLyrTbl1.Has(sLayerName1) == false)&lt;BR /&gt;{&lt;BR /&gt;acLyrTblRec = new LayerTableRecord();&lt;BR /&gt;// Assign the layer a name&lt;BR /&gt;acLyrTblRec.Name = sLayerName1;&lt;/P&gt;&lt;P&gt;// Upgrade the Layer table for write&lt;BR /&gt;if (acLyrTbl1.IsWriteEnabled == false) acLyrTbl1.UpgradeOpen();&lt;/P&gt;&lt;P&gt;// Append the new layer to the Layer table and the transaction&lt;BR /&gt;acLyrTbl1.Add(acLyrTblRec);&lt;BR /&gt;tr.AddNewlyCreatedDBObject(acLyrTblRec, true);&lt;BR /&gt;}&lt;BR /&gt;else&lt;BR /&gt;{&lt;BR /&gt;// Open the layer if it already exists for write&lt;BR /&gt;acLyrTblRec = tr.GetObject(acLyrTbl1[sLayerName1], OpenMode.ForWrite) as LayerTableRecord;&lt;/P&gt;&lt;P&gt;}&lt;/P&gt;&lt;P&gt;&lt;BR /&gt;//This function will import the selected dwg into modelspace and activate it&lt;BR /&gt;if (comboBox1.Text == "FACSPR7")&lt;BR /&gt;{&lt;BR /&gt;comp = "C:\\ACADSTUFF\\FACSPR7.dwg";&lt;BR /&gt;&lt;BR /&gt;}&lt;BR /&gt;if (comboBox1.Text == "FACSPR1")&lt;BR /&gt;{&lt;BR /&gt;comp = "C:\\ACADSTUFF\\FACSPR1.dwg";&lt;BR /&gt;&lt;BR /&gt;}&lt;BR /&gt;if (comboBox1.Text == "FACSPR17")&lt;BR /&gt;{&lt;BR /&gt;comp = "C:\\ACADSTUFF\\FACSPR17.dwg";&lt;BR /&gt;&lt;BR /&gt;}&lt;BR /&gt;if (comboBox1.Text == "FACSPR22")&lt;BR /&gt;{&lt;BR /&gt;comp = "C:\\ACADSTUFF\\FACSPR22.dwg";&lt;BR /&gt;&lt;BR /&gt;}&lt;BR /&gt;if (comboBox1.Text == "FACSPR31")&lt;BR /&gt;{&lt;BR /&gt;comp = "C:\\ACADSTUFF\\FACSPR31.dwg";&lt;BR /&gt;&lt;BR /&gt;}&lt;/P&gt;&lt;P&gt;string dwgName = HostApplicationServices.Current.FindFile(comp, acadApp.DocumentManager.MdiActiveDocument.Database, FindFileHint.Default);&lt;/P&gt;&lt;P&gt;Database db1 = new Database(false, false);&lt;/P&gt;&lt;P&gt;db1.ReadDwgFile(dwgName, System.IO.FileShare.Read, true, "");&lt;/P&gt;&lt;P&gt;ObjectId BlkId;&lt;/P&gt;&lt;P&gt;BlkId = doc.Database.Insert(dwgName, db1, false);&lt;/P&gt;&lt;P&gt;BlockTable bt = (BlockTable)tr.GetObject(doc.Database.BlockTableId, OpenMode.ForRead, true);&lt;/P&gt;&lt;P&gt;BlockTableRecord btr = (BlockTableRecord)tr.GetObject(bt[BlockTableRecord.ModelSpace], OpenMode.ForWrite);&lt;BR /&gt;&lt;BR /&gt;int quantity = Convert.ToInt32(numericUpDown1.Value);&lt;BR /&gt;Point3d pCenter = new Point3d(0, 0, 0);&lt;BR /&gt;Vector3d vOffset = new Vector3d(1000, 0, 0);&lt;BR /&gt;&lt;BR /&gt;for (int i = 0; i &amp;lt; quantity; i++)&lt;BR /&gt;{&lt;BR /&gt;&lt;BR /&gt;BlockReference bref = new BlockReference(pCenter, BlkId);&lt;/P&gt;&lt;P&gt;bref.Layer = "CH-SPR";&lt;/P&gt;&lt;P&gt;btr.AppendEntity(bref);&lt;/P&gt;&lt;P&gt;tr.AddNewlyCreatedDBObject(bref, true);&lt;/P&gt;&lt;P&gt;pCenter += vOffset;&lt;/P&gt;&lt;P&gt;bref.ExplodeToOwnerSpace();&lt;/P&gt;&lt;P&gt;bref.Erase();&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;}&lt;BR /&gt;&lt;BR /&gt;}&lt;BR /&gt;catch&lt;BR /&gt;{&lt;BR /&gt;MessageBox.Show("Failed to read the DWG from the refence folder, are you sure it is present?");&lt;BR /&gt;}&lt;BR /&gt;finally&lt;BR /&gt;{&lt;BR /&gt;tr.Commit();&lt;BR /&gt;this.Close();&lt;BR /&gt;}&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&lt;BR /&gt;}&lt;/P&gt;&lt;P&gt;}&lt;/P&gt;&lt;P&gt;private void numericUpDown1_ValueChanged(object sender, EventArgs e)&lt;BR /&gt;{&lt;/P&gt;&lt;P&gt;}&lt;/P&gt;&lt;P&gt;private void pictureBox1_Click(object sender, EventArgs e)&lt;BR /&gt;{&lt;/P&gt;&lt;P&gt;}&lt;BR /&gt;}&lt;/P&gt;&lt;P&gt;}&lt;/P&gt;</description>
      <pubDate>Wed, 25 Jan 2012 13:58:52 GMT</pubDate>
      <guid>https://forums.autodesk.com/t5/net-forum/repeatedly-insert-block/m-p/3305767#M57614</guid>
      <dc:creator>Anonymous</dc:creator>
      <dc:date>2012-01-25T13:58:52Z</dc:date>
    </item>
    <item>
      <title>Re: Repeatedly Insert Block</title>
      <link>https://forums.autodesk.com/t5/net-forum/repeatedly-insert-block/m-p/3305801#M57615</link>
      <description>&lt;P&gt;&lt;SPAN&gt;&lt;A target="_self" href="http://forums.autodesk.com/t5/user/viewprofilepage/user-id/918978"&gt;vince1327&lt;/A&gt;&amp;nbsp;you are assigning layer to the blockref then erase it after exploding so the individual entities' layers that comprise the block definition must be set in order to accomplish this task. Do you have to explode them?&lt;/SPAN&gt;&lt;/P&gt;</description>
      <pubDate>Wed, 25 Jan 2012 14:18:33 GMT</pubDate>
      <guid>https://forums.autodesk.com/t5/net-forum/repeatedly-insert-block/m-p/3305801#M57615</guid>
      <dc:creator>cincir</dc:creator>
      <dc:date>2012-01-25T14:18:33Z</dc:date>
    </item>
    <item>
      <title>Re: Repeatedly Insert Block</title>
      <link>https://forums.autodesk.com/t5/net-forum/repeatedly-insert-block/m-p/3305831#M57616</link>
      <description>&lt;P&gt;Hey Cincir,&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;The reason that i'm exploding them to ownerspace is because that is the only way that I can get them to show up on the actual drawing. Is there another way?&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;Cheers&lt;/P&gt;</description>
      <pubDate>Wed, 25 Jan 2012 14:33:48 GMT</pubDate>
      <guid>https://forums.autodesk.com/t5/net-forum/repeatedly-insert-block/m-p/3305831#M57616</guid>
      <dc:creator>Anonymous</dc:creator>
      <dc:date>2012-01-25T14:33:48Z</dc:date>
    </item>
    <item>
      <title>Re: Repeatedly Insert Block</title>
      <link>https://forums.autodesk.com/t5/net-forum/repeatedly-insert-block/m-p/3305889#M57617</link>
      <description>&lt;P&gt;comment the explodetomodelspce and erase lines and see what will you get &lt;span class="lia-unicode-emoji" title=":slightly_smiling_face:"&gt;🙂&lt;/span&gt;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Wed, 25 Jan 2012 15:02:57 GMT</pubDate>
      <guid>https://forums.autodesk.com/t5/net-forum/repeatedly-insert-block/m-p/3305889#M57617</guid>
      <dc:creator>cincir</dc:creator>
      <dc:date>2012-01-25T15:02:57Z</dc:date>
    </item>
    <item>
      <title>Re: Repeatedly Insert Block</title>
      <link>https://forums.autodesk.com/t5/net-forum/repeatedly-insert-block/m-p/3305931#M57618</link>
      <description>&lt;P&gt;Cool, so that brough it in as a block reference on the correct layer. The problem though is that I need all the attributes that it would normally have if it was exploded...So right now i'm stuck at crossroads...I can have it brought in and explode it, but it's in the wrong layer...or I could bring it into the correct layer as a block reference but not have any of my attributes...is there a middle ground somewhere. Can i explode it and then transfer it to the correct layer?&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;Thanks so much!&lt;/P&gt;</description>
      <pubDate>Wed, 25 Jan 2012 15:22:00 GMT</pubDate>
      <guid>https://forums.autodesk.com/t5/net-forum/repeatedly-insert-block/m-p/3305931#M57618</guid>
      <dc:creator>Anonymous</dc:creator>
      <dc:date>2012-01-25T15:22:00Z</dc:date>
    </item>
    <item>
      <title>Re: Repeatedly Insert Block</title>
      <link>https://forums.autodesk.com/t5/net-forum/repeatedly-insert-block/m-p/3305963#M57619</link>
      <description>&lt;P&gt;you are at the wrong tides. your blockreference can have all the attributedefinitions as your blockdefinition as attributereference. &lt;span class="lia-unicode-emoji" title=":winking_face:"&gt;😉&lt;/span&gt;&lt;/P&gt;</description>
      <pubDate>Wed, 25 Jan 2012 15:39:16 GMT</pubDate>
      <guid>https://forums.autodesk.com/t5/net-forum/repeatedly-insert-block/m-p/3305963#M57619</guid>
      <dc:creator>cincir</dc:creator>
      <dc:date>2012-01-25T15:39:16Z</dc:date>
    </item>
    <item>
      <title>Re: Repeatedly Insert Block</title>
      <link>https://forums.autodesk.com/t5/net-forum/repeatedly-insert-block/m-p/3305969#M57620</link>
      <description>&lt;P&gt;hey cincir, i'm not sure what you mean by this...sorry i'm actually very new to this and sometimes the terminology along with the api are very confusing. How do i implement the attributereference that you're talking about?&lt;/P&gt;</description>
      <pubDate>Wed, 25 Jan 2012 15:42:37 GMT</pubDate>
      <guid>https://forums.autodesk.com/t5/net-forum/repeatedly-insert-block/m-p/3305969#M57620</guid>
      <dc:creator>Anonymous</dc:creator>
      <dc:date>2012-01-25T15:42:37Z</dc:date>
    </item>
    <item>
      <title>Re: Repeatedly Insert Block</title>
      <link>https://forums.autodesk.com/t5/net-forum/repeatedly-insert-block/m-p/3306045#M57621</link>
      <description>&lt;PRE&gt;BlkId = doc.Database.Insert(dwgName, db1, false);
BlockTable bt = (BlockTable)tr.GetObject(doc.Database.BlockTableId, OpenMode.ForRead, true);
BlockTableRecord btr = (BlockTableRecord)tr.GetObject(bt[BlockTableRecord.ModelSpace], OpenMode.ForWrite);

int quantity = Convert.ToInt32(numericUpDown1.Value);
Point3d pCenter = new Point3d(0, 0, 0);
Vector3d vOffset = new Vector3d(1000, 0, 0);

BlockTableRecord acBlkDef = acTrans.GetObject(BlkId,OpenMode.ForRead) as BlockTableRecord;

for (int i = 0; i &amp;lt; quantity; i++)
{
   BlockReference bref = new BlockReference(pCenter, BlkId);
   
   if (acBlkDef.HasAttributeDefinitions)
   {
      foreach(ObjectId acAttId in acBlkDef)
      {
         Entity acTempEnt = (Entity)acTrans.GetObject(acAttId,OpenMode.ForRead);
         if (acTempEnt is AttributeDefinition)
         {
             AttributeReference acAttRef = new AttributeReference();
              acAttRef.SetAttributeFromBlock((AttributeDefinition)acTempEnt,bref.BlockTransform);
             acAttRef.Layer = "CH-SPR";
             bref.AttributeCollection.AppendAttribute(acAttRef);
             acTrans.AddNewlyCreatedDBObject(acAttRef,true);  
         }
         
      }
   }
   
   bref.Layer = "CH-SPR";
   btr.AppendEntity(bref);
   tr.AddNewlyCreatedDBObject(bref, true);
   pCenter += vOffset;
}&lt;/PRE&gt;&lt;P&gt;&amp;nbsp;it is hard to write code without Visual Studio Intellisence &lt;span class="lia-unicode-emoji" title=":slightly_smiling_face:"&gt;🙂&lt;/span&gt;&lt;/P&gt;</description>
      <pubDate>Wed, 25 Jan 2012 16:09:18 GMT</pubDate>
      <guid>https://forums.autodesk.com/t5/net-forum/repeatedly-insert-block/m-p/3306045#M57621</guid>
      <dc:creator>cincir</dc:creator>
      <dc:date>2012-01-25T16:09:18Z</dc:date>
    </item>
  </channel>
</rss>

