<?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 Add entities to new block in .NET Forum</title>
    <link>https://forums.autodesk.com/t5/net-forum/add-entities-to-new-block/m-p/2897352#M62029</link>
    <description>&lt;P&gt;Working with making blocks from existing entities in a file. I've run into problems with iterating through the entities within a selection set and writing them to my new blocktablerecord. How do I take those items from my selection set and add them to this new block? All thoughts and help are appreciated.&amp;nbsp;&lt;/P&gt;</description>
    <pubDate>Fri, 28 Jan 2011 16:35:18 GMT</pubDate>
    <dc:creator>MRiemenCAD</dc:creator>
    <dc:date>2011-01-28T16:35:18Z</dc:date>
    <item>
      <title>Add entities to new block</title>
      <link>https://forums.autodesk.com/t5/net-forum/add-entities-to-new-block/m-p/2897352#M62029</link>
      <description>&lt;P&gt;Working with making blocks from existing entities in a file. I've run into problems with iterating through the entities within a selection set and writing them to my new blocktablerecord. How do I take those items from my selection set and add them to this new block? All thoughts and help are appreciated.&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Fri, 28 Jan 2011 16:35:18 GMT</pubDate>
      <guid>https://forums.autodesk.com/t5/net-forum/add-entities-to-new-block/m-p/2897352#M62029</guid>
      <dc:creator>MRiemenCAD</dc:creator>
      <dc:date>2011-01-28T16:35:18Z</dc:date>
    </item>
    <item>
      <title>Re: Add entities to new block</title>
      <link>https://forums.autodesk.com/t5/net-forum/add-entities-to-new-block/m-p/2897396#M62030</link>
      <description>&lt;P&gt;You can:&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;UL&gt;&lt;LI&gt;Manually create the new BlockTableRecord and BlockTable.Add() it, then&lt;/LI&gt;&lt;LI&gt;Database.DeepCloneObjects() into your new BlockTableRecord&lt;/LI&gt;&lt;/UL&gt;&lt;DIV&gt;or:&lt;/DIV&gt;&lt;UL&gt;&lt;LI&gt;Database.WBlock(ObjectIdCollection,Point3d) to create a new, temporary database containing your objects, then&lt;/LI&gt;&lt;LI&gt;Database.Insert(string, Database, bool) to create your new BlockTableRecord&lt;/LI&gt;&lt;/UL&gt;&lt;DIV&gt;or (if you don't mind deleting that the existing entities are _moved_ to the new BlockTableRecord rather than copied):&lt;/DIV&gt;&lt;DIV&gt;&lt;UL&gt;&lt;LI&gt;Manually create the new BlockTableRecord and BlockTable.Add() it, then&lt;/LI&gt;&lt;LI&gt;BlockTableRecord.AssumeOwnershipOf()&lt;/LI&gt;&lt;/UL&gt;&lt;/DIV&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Fri, 28 Jan 2011 17:05:01 GMT</pubDate>
      <guid>https://forums.autodesk.com/t5/net-forum/add-entities-to-new-block/m-p/2897396#M62030</guid>
      <dc:creator>Anonymous</dc:creator>
      <dc:date>2011-01-28T17:05:01Z</dc:date>
    </item>
    <item>
      <title>Re: Add entities to new block</title>
      <link>https://forums.autodesk.com/t5/net-forum/add-entities-to-new-block/m-p/2897422#M62031</link>
      <description>&lt;P&gt;Thanks,&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;I like the "AssumeOwnershipOf" route that you suggest. When I use this on the&amp;nbsp;selection&amp;nbsp;set I'm told that the set &amp;nbsp;cannot be converted into and ObjectIDCollection. May this I'm missing a simple step in working with selection sets. Is there an easy way to take the objects from the selection set, create a suitable IDCollection and then pass that collection to the "AssumeOwnershipOf" method?&lt;/P&gt;&lt;DIV&gt;Matt&lt;/DIV&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Fri, 28 Jan 2011 17:16:10 GMT</pubDate>
      <guid>https://forums.autodesk.com/t5/net-forum/add-entities-to-new-block/m-p/2897422#M62031</guid>
      <dc:creator>MRiemenCAD</dc:creator>
      <dc:date>2011-01-28T17:16:10Z</dc:date>
    </item>
    <item>
      <title>Re: Add entities to new block</title>
      <link>https://forums.autodesk.com/t5/net-forum/add-entities-to-new-block/m-p/2897434#M62032</link>
      <description>&lt;P&gt;Yup. &amp;nbsp;The ObjectIdCollection constructor can take an ObjectId array as an argument, which is what SelectionSet.GetObjectIds() provides.&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;Put another way...&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;Dim ids as ObjectIdCollection = New ObjectIdCollection(sset.GetObjectIds)&lt;/P&gt;</description>
      <pubDate>Fri, 28 Jan 2011 17:21:17 GMT</pubDate>
      <guid>https://forums.autodesk.com/t5/net-forum/add-entities-to-new-block/m-p/2897434#M62032</guid>
      <dc:creator>Anonymous</dc:creator>
      <dc:date>2011-01-28T17:21:17Z</dc:date>
    </item>
    <item>
      <title>Re: Add entities to new block</title>
      <link>https://forums.autodesk.com/t5/net-forum/add-entities-to-new-block/m-p/2897446#M62033</link>
      <description>&lt;P&gt;Something like this&lt;/P&gt;&lt;P&gt;Just a hint starting the new thread you will be able to get a much more explanations&lt;/P&gt;&lt;P&gt;because of hiding your question at the end of thread&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;PRE&gt;Imports System
Imports System.Text
Imports acApp = Autodesk.AutoCAD.ApplicationServices.Application
Imports Autodesk.AutoCAD.Runtime
Imports Autodesk.AutoCAD.ApplicationServices
Imports Autodesk.AutoCAD.DatabaseServices
Imports Autodesk.AutoCAD.EditorInput
Imports Autodesk.AutoCAD.Geometry



Public Class TesterCommands
    &amp;lt;CommandMethod("bobo", CommandFlags.UsePickSet)&amp;gt; _
    Public Sub MakeBlockFromSelection()

        Dim doc As Document = acApp.DocumentManager.MdiActiveDocument

        Dim db As Database = doc.Database

        Dim ed As Editor = doc.Editor

        Using docloc As DocumentLock = doc.LockDocument

            Using tr As Transaction = db.TransactionManager.StartTransaction

                Try

                    Dim pso As New PromptSelectionOptions()

                    pso.MessageForRemoval = vbLf &amp;amp; " &amp;gt;&amp;gt;  Nothing selected...."

                    pso.MessageForAdding = vbLf &amp;amp; "  &amp;gt;&amp;gt;  Select objects &amp;gt;&amp;gt; "

                    pso.AllowDuplicates = False

                    pso.SingleOnly = True

                    Dim res As PromptSelectionResult = ed.GetSelection(pso)

                    If res.Status &amp;lt;&amp;gt; PromptStatus.OK Then
                        Return
                    End If

                    Dim ids As ObjectId() = res.Value.GetObjectIds()

                    If ids.Length = 0 Then
                        Return
                    End If

                    Dim ppo As New PromptPointOptions(vbLf &amp;amp; "Pick insertion point for newly created block &amp;gt;&amp;gt;")

                    Dim pres As PromptPointResult = ed.GetPoint(ppo)

                    If pres.Status &amp;lt;&amp;gt; PromptStatus.OK Then

                        Return
                    End If

                    Dim ip As Point3d = pres.Value

                    Dim bt As BlockTable = DirectCast(db.BlockTableId.GetObject(OpenMode.ForWrite), BlockTable)


                    Dim newname As String = "MyCoolBlock"

                    If bt.Has(newname) Then
                        ed.WriteMessage(vbLf &amp;amp; "Block ""{0}"" already exist", newname)

                        Return
                    End If

                    Dim bids As New ObjectIdCollection()

                    For Each eid As ObjectId In ids

                        bids.Add(eid)
                    Next

                    acApp.SetSystemVariable("clayer", "0")

                    acApp.SetSystemVariable("cecolor", "bylayer")

                    Dim nbtr As New BlockTableRecord()

                    bt.Add(nbtr)

                    nbtr.Name = newname

                    nbtr.Origin = ip


                    nbtr.BlockScaling = BlockScaling.Uniform

                    nbtr.Explodable = True

                    tr.AddNewlyCreatedDBObject(nbtr, True)


                    Dim map As New IdMapping()

                    db.DeepCloneObjects(bids, nbtr.ObjectId, map, False)

                    Dim coll As New ObjectIdCollection()

                    For Each pair As IdPair In map
                        If pair.IsPrimary Then
                            Dim ent As Entity = DirectCast(tr.GetObject(pair.Value, OpenMode.ForWrite), Entity)
                            If ent IsNot Nothing Then
                                ent.Layer = "0"

                                ent.ColorIndex = 0
                                If (TypeOf (ent) Is AttributeDefinition) Then
                                    Dim att As AttributeDefinition = DirectCast(ent, AttributeDefinition)
                                    att.LockPositionInBlock = True
                                End If
                                '&amp;lt;-- color byblock
                                coll.Add(ent.ObjectId)
                            End If
                        End If
                    Next

                    nbtr.AssumeOwnershipOf(coll)


                    tr.Commit()
                Catch ex As Autodesk.AutoCAD.Runtime.Exception

                    ed.WriteMessage(vbLf + ex.Message + vbLf + ex.StackTrace)

                End Try
            End Using
        End Using

    End Sub

End Class&lt;/PRE&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;~'J'~&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;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Fri, 28 Jan 2011 17:24:09 GMT</pubDate>
      <guid>https://forums.autodesk.com/t5/net-forum/add-entities-to-new-block/m-p/2897446#M62033</guid>
      <dc:creator>Hallex</dc:creator>
      <dc:date>2011-01-28T17:24:09Z</dc:date>
    </item>
    <item>
      <title>Re: Add entities to new block</title>
      <link>https://forums.autodesk.com/t5/net-forum/add-entities-to-new-block/m-p/2897496#M62034</link>
      <description>&lt;P&gt;Thanks for your post. I thought that your previous comment to the original string was close to the sollution i was after so i tried targetting my question.&amp;nbsp;&lt;img id="smileyhappy" class="emoticon emoticon-smileyhappy" src="https://forums.autodesk.com/i/smilies/16x16_smiley-happy.png" alt="Smiley Happy" title="Smiley Happy" /&gt;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;thanks for you reply. It worked great. I'll study through it to see what I missed on my own.&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;regards,&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;matt&lt;/P&gt;</description>
      <pubDate>Fri, 28 Jan 2011 17:42:01 GMT</pubDate>
      <guid>https://forums.autodesk.com/t5/net-forum/add-entities-to-new-block/m-p/2897496#M62034</guid>
      <dc:creator>MRiemenCAD</dc:creator>
      <dc:date>2011-01-28T17:42:01Z</dc:date>
    </item>
    <item>
      <title>Re: Add entities to new block</title>
      <link>https://forums.autodesk.com/t5/net-forum/add-entities-to-new-block/m-p/2897816#M62035</link>
      <description>&lt;P&gt;You're welcome&lt;/P&gt;&lt;P&gt;&amp;nbsp;Cheers &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;Oleg&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;~'J'~&lt;/P&gt;</description>
      <pubDate>Fri, 28 Jan 2011 21:00:00 GMT</pubDate>
      <guid>https://forums.autodesk.com/t5/net-forum/add-entities-to-new-block/m-p/2897816#M62035</guid>
      <dc:creator>Hallex</dc:creator>
      <dc:date>2011-01-28T21:00:00Z</dc:date>
    </item>
    <item>
      <title>Re: Add entities to new block</title>
      <link>https://forums.autodesk.com/t5/net-forum/add-entities-to-new-block/m-p/5445702#M62036</link>
      <description>&lt;P&gt;It's a good solution to my problem. Thanks!&lt;/P&gt;</description>
      <pubDate>Wed, 17 Dec 2014 01:57:43 GMT</pubDate>
      <guid>https://forums.autodesk.com/t5/net-forum/add-entities-to-new-block/m-p/5445702#M62036</guid>
      <dc:creator>Anonymous</dc:creator>
      <dc:date>2014-12-17T01:57:43Z</dc:date>
    </item>
  </channel>
</rss>

