<?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 Block From another File in .NET Forum</title>
    <link>https://forums.autodesk.com/t5/net-forum/insert-block-from-another-file/m-p/3773769#M54708</link>
    <description>&lt;P&gt;Could I see that code? I've been struggling with this concept and have dropped it several times, resorting to Lisp.&lt;/P&gt;</description>
    <pubDate>Fri, 08 Feb 2013 22:17:56 GMT</pubDate>
    <dc:creator>Anonymous</dc:creator>
    <dc:date>2013-02-08T22:17:56Z</dc:date>
    <item>
      <title>Insert Block From another File</title>
      <link>https://forums.autodesk.com/t5/net-forum/insert-block-from-another-file/m-p/3527080#M54704</link>
      <description>&lt;P&gt;&lt;STRONG&gt;Hi Guys,&lt;/STRONG&gt;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;I am inserting a block from another file to the current drawing file.&lt;/P&gt;&lt;P&gt;I am using C#.Net.&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;My block gets added into the blocktable record of the current file, but while inserting the block using the "Block" command in AutoCAD its shows an error&amp;nbsp;&lt;U&gt;"The Existing Block has not been modified" &lt;/U&gt;I have attached a screenshot of the message i am getting.&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;I want to insert the block automatically to a user specified location.&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;How to resolve it ?&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&lt;STRONG&gt;Thank You&lt;/STRONG&gt;&lt;/P&gt;</description>
      <pubDate>Thu, 05 Jul 2012 09:28:48 GMT</pubDate>
      <guid>https://forums.autodesk.com/t5/net-forum/insert-block-from-another-file/m-p/3527080#M54704</guid>
      <dc:creator>Anonymous</dc:creator>
      <dc:date>2012-07-05T09:28:48Z</dc:date>
    </item>
    <item>
      <title>Re: Insert Block From another File</title>
      <link>https://forums.autodesk.com/t5/net-forum/insert-block-from-another-file/m-p/3527162#M54705</link>
      <description>&lt;P&gt;Below is code for how&amp;nbsp;I have added blocks in VB.Net.&lt;/P&gt;&lt;P&gt;Note that in this case I added blocks to paperspace but you can change that easily.&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;PRE&gt;Dim BlkFullPath As String
                        Dim currDwgDB As Database = myAcadApp.DocumentManager.MdiActiveDocument.Database
                        Try
                            ' Awesome! this seaches the support paths for the file and if found returns the full path with file name.  
                            BlkFullPath = HostApplicationServices.Current.FindFile(BlkName &amp;amp; ".dwg", currDwgDB, FindFileHint.Default)
                        Catch ex As Autodesk.AutoCAD.Runtime.Exception
                            MessageBox.Show(ex.Message &amp;amp; ": " &amp;amp; BlkName &amp;amp; ".dwg" &amp;amp; " not found in support paths.", "", MessageBoxButtons.OK, MessageBoxIcon.Exclamation)
                            Exit Sub
                        End Try

                        Using acLckDoc As DocumentLock = SheetDoc.LockDocument()

                            Using trx As Transaction = mySheetDB.TransactionManager.StartTransaction
                                Dim ObjId As ObjectId
                                Dim bt As BlockTable = mySheetDB.BlockTableId.GetObject(OpenMode.ForRead)
                                Dim btrMs As BlockTableRecord = bt(BlockTableRecord.PaperSpace).GetObject(OpenMode.ForWrite)
                                Using dbInsert As New Database(False, True)
                                    dbInsert.ReadDwgFile(BlkFullPath, IO.FileShare.Read, True, "")
                                    ObjId = mySheetDB.Insert(Path.GetFileNameWithoutExtension(BlkFullPath), dbInsert, True)
                                End Using

                                Dim BlkRef As New BlockReference(New Point3d(BlkX, BlkY, 0), ObjId)
                                btrMs.AppendEntity(BlkRef)
                                trx.AddNewlyCreatedDBObject(BlkRef, True)

                                ' explode the block
                                BlkRef.ExplodeToOwnerSpace()
                                ' when using ExplodeToOwnerSpace, if you dont do this then the block is retained in the drawing.
                                BlkRef.Erase(True)

                                trx.Commit()
                            End Using
                        End Using&lt;/PRE&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;.&lt;/P&gt;&lt;P&gt;Note that in this&amp;nbsp;case Im adding to PaperSpace but you can change that.&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Thu, 05 Jul 2012 11:58:56 GMT</pubDate>
      <guid>https://forums.autodesk.com/t5/net-forum/insert-block-from-another-file/m-p/3527162#M54705</guid>
      <dc:creator>jshimkus</dc:creator>
      <dc:date>2012-07-05T11:58:56Z</dc:date>
    </item>
    <item>
      <title>Re: Insert Block From another File</title>
      <link>https://forums.autodesk.com/t5/net-forum/insert-block-from-another-file/m-p/3527202#M54706</link>
      <description>&lt;P&gt;&lt;STRONG&gt;Hi CommCorp,&lt;/STRONG&gt;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;Will Try and post the result back&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&lt;STRONG&gt;Thank You for your time&lt;/STRONG&gt;&lt;/P&gt;</description>
      <pubDate>Thu, 05 Jul 2012 12:28:19 GMT</pubDate>
      <guid>https://forums.autodesk.com/t5/net-forum/insert-block-from-another-file/m-p/3527202#M54706</guid>
      <dc:creator>Anonymous</dc:creator>
      <dc:date>2012-07-05T12:28:19Z</dc:date>
    </item>
    <item>
      <title>Re: Insert Block From another File</title>
      <link>https://forums.autodesk.com/t5/net-forum/insert-block-from-another-file/m-p/3528634#M54707</link>
      <description>&lt;P&gt;&lt;STRONG&gt;Hi,&lt;/STRONG&gt;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;I actually was not inserting a block i was just adding it to the blocktable record, thats why i was getting an error,&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;When i looked at the last segment of your code i remembered what i missed.&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;I finshed the task sucessfully &amp;amp; just to inform you, i wrote the code in C#&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&lt;STRONG&gt;Thank You for the solution&lt;/STRONG&gt;&lt;/P&gt;</description>
      <pubDate>Fri, 06 Jul 2012 05:34:41 GMT</pubDate>
      <guid>https://forums.autodesk.com/t5/net-forum/insert-block-from-another-file/m-p/3528634#M54707</guid>
      <dc:creator>Anonymous</dc:creator>
      <dc:date>2012-07-06T05:34:41Z</dc:date>
    </item>
    <item>
      <title>Re: Insert Block From another File</title>
      <link>https://forums.autodesk.com/t5/net-forum/insert-block-from-another-file/m-p/3773769#M54708</link>
      <description>&lt;P&gt;Could I see that code? I've been struggling with this concept and have dropped it several times, resorting to Lisp.&lt;/P&gt;</description>
      <pubDate>Fri, 08 Feb 2013 22:17:56 GMT</pubDate>
      <guid>https://forums.autodesk.com/t5/net-forum/insert-block-from-another-file/m-p/3773769#M54708</guid>
      <dc:creator>Anonymous</dc:creator>
      <dc:date>2013-02-08T22:17:56Z</dc:date>
    </item>
    <item>
      <title>Re: Insert Block From another File</title>
      <link>https://forums.autodesk.com/t5/net-forum/insert-block-from-another-file/m-p/3773967#M54709</link>
      <description>&lt;P&gt;Find the below code, Alter as per your needs.&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;Find the code below, Alter as per your needs...&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;public void AddBlocktoDataBase()&lt;BR /&gt;{&lt;BR /&gt;Document doc = Application.DocumentManager.MdiActiveDocument;&lt;BR /&gt;using (Database OpenDb = new Database(false, true))&lt;BR /&gt;{&lt;BR /&gt;PromptStringOptions pStrOpts = new PromptStringOptions("Ask for the template like 1,2,3,4,etc");&lt;BR /&gt;pStrOpts.AllowSpaces = false;&lt;/P&gt;&lt;P&gt;PromptResult pStrRes = doc.Editor.GetString(pStrOpts);&lt;/P&gt;&lt;P&gt;if (pStrRes.Status != PromptStatus.OK)&lt;BR /&gt;return;&lt;/P&gt;&lt;P&gt;if (pStrRes.StringResult.Equals("1"))&lt;BR /&gt;{&lt;BR /&gt;OpenDb.ReadDwgFile("Template path here", System.IO.FileShare.ReadWrite, true, "");&lt;BR /&gt;blkname = "TPS-A1-Manufacturing-India";&lt;BR /&gt;}&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&lt;SPAN&gt;ObjectIdCollection ids = new ObjectIdCollection();&lt;/SPAN&gt;&lt;/P&gt;&lt;P&gt;using (Transaction tr = OpenDb.TransactionManager.StartTransaction())&lt;BR /&gt;{&lt;BR /&gt;//For example, Get the block by name "BlkName"&lt;BR /&gt;BlockTable bt;&lt;BR /&gt;bt = (BlockTable)tr.GetObject(OpenDb.BlockTableId, OpenMode.ForRead);&lt;/P&gt;&lt;P&gt;if (bt.Has(blockkname))&lt;BR /&gt;{&lt;BR /&gt;ids.Add(bt[blockname]);&lt;BR /&gt;}&lt;BR /&gt;tr.Commit();&lt;BR /&gt;}&lt;/P&gt;&lt;P&gt;//if found, add the block&lt;BR /&gt;if (ids.Count != 0)&lt;BR /&gt;{&lt;BR /&gt;//get the current drawing database&lt;BR /&gt;Database destdb = doc.Database;&lt;/P&gt;&lt;P&gt;IdMapping iMap = new IdMapping();&lt;BR /&gt;destdb.WblockCloneObjects(ids, destdb.BlockTableId, iMap, DuplicateRecordCloning.Ignore, false);&lt;/P&gt;&lt;P&gt;}&lt;BR /&gt;}&amp;nbsp;&lt;BR /&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;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;public void AddBlocktoModelSpace()&lt;BR /&gt;{&lt;BR /&gt;Database db = Application.DocumentManager.MdiActiveDocument.Database;&lt;BR /&gt;using (Transaction myT = db.TransactionManager.StartTransaction())&lt;BR /&gt;{&lt;BR /&gt;//Get the block definition "Check".&lt;BR /&gt;BlockTable bt = db.BlockTableId.GetObject(OpenMode.ForRead) as BlockTable;&lt;BR /&gt;BlockTableRecord blockDef = bt[blockname].GetObject(OpenMode.ForRead) as BlockTableRecord;&lt;BR /&gt;//Also open modelspace - we'll be adding our BlockReference to it&lt;BR /&gt;BlockTableRecord ms = bt[BlockTableRecord.ModelSpace].GetObject(OpenMode.ForWrite) as BlockTableRecord;&lt;BR /&gt;//Create new BlockReference, and link it to our block definition&lt;/P&gt;&lt;P&gt;using (BlockReference blockRef = new BlockReference(insertionpoint, blockDef.ObjectId))&lt;BR /&gt;{&lt;BR /&gt;//Add the block reference to modelspace&lt;BR /&gt;ms.AppendEntity(blockRef);&lt;BR /&gt;myT.AddNewlyCreatedDBObject(blockRef, true);&lt;BR /&gt;//Iterate block definition to find all non-constant&lt;BR /&gt;// AttributeDefinitions&lt;/P&gt;&lt;P&gt;foreach (ObjectId id in blockDef)&lt;BR /&gt;{&lt;BR /&gt;DBObject obj = id.GetObject(OpenMode.ForRead);&lt;BR /&gt;AttributeDefinition attDef = obj as AttributeDefinition;&lt;BR /&gt;if ((attDef != null) &amp;amp;&amp;amp; (!attDef.Constant))&lt;BR /&gt;{&lt;BR /&gt;//This is a non-constant AttributeDefinition&lt;BR /&gt;//Create a new AttributeReference&lt;BR /&gt;using (AttributeReference attRef = new AttributeReference())&lt;BR /&gt;{&lt;BR /&gt;attRef.SetAttributeFromBlock(attDef, blockRef.BlockTransform);&lt;BR /&gt;//attRef.TextString = "Santosh";&lt;BR /&gt;//Add the AttributeReference to the BlockReference&lt;BR /&gt;blockRef.AttributeCollection.AppendAttribute(attRef);&lt;BR /&gt;myT.AddNewlyCreatedDBObject(attRef, true);&lt;BR /&gt;}&lt;BR /&gt;}&lt;BR /&gt;}&lt;BR /&gt;}&lt;BR /&gt;//Our work here is done&lt;BR /&gt;myT.Commit();&lt;BR /&gt;}&lt;BR /&gt;}&lt;/P&gt;</description>
      <pubDate>Sat, 09 Feb 2013 09:47:26 GMT</pubDate>
      <guid>https://forums.autodesk.com/t5/net-forum/insert-block-from-another-file/m-p/3773967#M54709</guid>
      <dc:creator>Anonymous</dc:creator>
      <dc:date>2013-02-09T09:47:26Z</dc:date>
    </item>
  </channel>
</rss>

