<?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: Modifying Entities Inside of a cloned BlockReference also changes the origin in .NET Forum</title>
    <link>https://forums.autodesk.com/t5/net-forum/modifying-entities-inside-of-a-cloned-blockreference-also/m-p/7380249#M29653</link>
    <description>&lt;P&gt;Hi, IMO you can&amp;nbsp;explode the blockreference. Then you have all the contents of the blockreference as separate entities.&lt;/P&gt;&lt;P&gt;Then you can do whatever you like with them.&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;From Through-the-interface (&lt;A href="http://through-the-interface.typepad.com/through_the_interface/2011/02/exploding-autocad-objects-using-net.html" target="_blank"&gt;http://through-the-interface.typepad.com/through_the_interface/2011/02/exploding-autocad-objects-using-net.html&lt;/A&gt;&lt;span class="lia-unicode-emoji" title=":disappointed_face:"&gt;😞&lt;/span&gt;&lt;/P&gt;&lt;P&gt;&lt;SPAN&gt;Entity.Explode() is one of those tricky methods: it’s actually a&amp;nbsp;&lt;/SPAN&gt;&lt;A href="http://en.wikipedia.org/wiki/False_friend" target="_blank"&gt;faux-ami&lt;/A&gt;&lt;SPAN&gt;&amp;nbsp;with the AutoCAD command of the same name, in a very similar way to Database.Purge(). The way in which Explode() and Purge() differ from their “equivalent” commands is that they’re non-destructive: they don’t actually result in a change to the AutoCAD drawing database. Explode() populates a DBObjectCollection with the results of the explode operation, and it’s then up to the caller of the function to add them to the appropriate location (typically the current – i.e. model- or paper- – space). Purge() checks a list of objects for ones that can safely be erased, and then it’s up to the caller of the function to do so.&lt;/SPAN&gt;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&lt;SPAN&gt;So using&lt;/SPAN&gt;&lt;/P&gt;&lt;P&gt;&lt;SPAN&gt;DBObjectCollection&amp;nbsp;objs =&amp;nbsp;new&amp;nbsp;DBObjectCollection();&lt;/SPAN&gt;&lt;/P&gt;&lt;P&gt;&lt;SPAN&gt;entity.Explode(objs);&lt;/SPAN&gt;&lt;/P&gt;&lt;P&gt;&lt;SPAN&gt;foreach&lt;/SPAN&gt;&lt;SPAN&gt;&amp;nbsp;(&lt;/SPAN&gt;&lt;SPAN&gt;DBObject&lt;/SPAN&gt;&lt;SPAN&gt;&amp;nbsp;obj&amp;nbsp;&lt;/SPAN&gt;&lt;SPAN&gt;in&lt;/SPAN&gt;&lt;SPAN&gt;&amp;nbsp;objs)&lt;/SPAN&gt;&lt;/P&gt;&lt;P&gt;&lt;SPAN&gt;{&lt;/SPAN&gt;&lt;/P&gt;&lt;P&gt;&lt;SPAN&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&lt;/SPAN&gt;&lt;SPAN&gt;Entity&lt;/SPAN&gt;&lt;SPAN&gt;&amp;nbsp;ent = (&lt;/SPAN&gt;&lt;SPAN&gt;Entity&lt;/SPAN&gt;&lt;SPAN&gt;)obj;&lt;/SPAN&gt;&lt;/P&gt;&lt;P&gt;&lt;SPAN&gt;// Modify to your wishes&lt;/SPAN&gt;&lt;/P&gt;&lt;P&gt;&lt;SPAN&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; btr.AppendEntity(ent);&lt;/SPAN&gt;&lt;/P&gt;&lt;P&gt;&lt;SPAN&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; tr.AddNewlyCreatedDBObject(ent,&amp;nbsp;&lt;/SPAN&gt;&lt;SPAN&gt;true&lt;/SPAN&gt;&lt;SPAN&gt;);&lt;/SPAN&gt;&lt;/P&gt;&lt;P&gt;&lt;SPAN&gt;}&lt;/SPAN&gt;&lt;/P&gt;&lt;P&gt;&lt;SPAN&gt;You'll have the blockreference (ent) still in your drawing, but also have all objects from within the block added to the drawing.&lt;/SPAN&gt;&lt;/P&gt;&lt;P&gt;&lt;SPAN&gt;&amp;nbsp;&lt;/SPAN&gt;&lt;/P&gt;&lt;P&gt;&lt;SPAN&gt;HTH,&lt;/SPAN&gt;&lt;/P&gt;&lt;P&gt;&lt;SPAN&gt;Sietse Wijnker&lt;/SPAN&gt;&lt;/P&gt;</description>
    <pubDate>Thu, 14 Sep 2017 11:55:04 GMT</pubDate>
    <dc:creator>Anonymous</dc:creator>
    <dc:date>2017-09-14T11:55:04Z</dc:date>
    <item>
      <title>Modifying Entities Inside of a cloned BlockReference also changes the original.</title>
      <link>https://forums.autodesk.com/t5/net-forum/modifying-entities-inside-of-a-cloned-blockreference-also/m-p/7374696#M29650</link>
      <description>&lt;P&gt;&amp;nbsp;I am trying to edit the&amp;nbsp;Entities inside of a cloned block without changing the entities of the original. Any help would be appreciated.&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;PRE&gt;var acBlkTbl = tr.GetObject(Active.Database.BlockTableId, OpenMode.ForRead) as BlockTable;&lt;BR /&gt;var acBlkTblRec = tr.GetObject(acBlkTbl[BlockTableRecord.ModelSpace], OpenMode.ForWrite) as BlockTableRecord;&lt;BR /&gt;BlockReference blockCopy = block.Clone() as BlockReference;
BlockTableRecord selectedBlockBTR = blockCopy.BlockTableRecord.GetObject(OpenMode.ForWrite) as BlockTableRecord;
foreach (ObjectId innerObjectId in selectedBlockBTR)
 {
   Entity ent = (Entity)tr.GetObject(innerObjectId, OpenMode.ForWrite);
   ent.Color = Color.FromColorIndex(ColorMethod.ByPen, 5);                    
 }&lt;BR /&gt; acBlkTblRec.AppendEntity(blockCopy);&lt;BR /&gt; tr.AddNewlyCreatedDBObject(blockCopy, true);&lt;/PRE&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Tue, 12 Sep 2017 20:50:19 GMT</pubDate>
      <guid>https://forums.autodesk.com/t5/net-forum/modifying-entities-inside-of-a-cloned-blockreference-also/m-p/7374696#M29650</guid>
      <dc:creator>gotMorris</dc:creator>
      <dc:date>2017-09-12T20:50:19Z</dc:date>
    </item>
    <item>
      <title>Re: Modifying Entities Inside of a cloned BlockReference also changes the origin</title>
      <link>https://forums.autodesk.com/t5/net-forum/modifying-entities-inside-of-a-cloned-blockreference-also/m-p/7374743#M29651</link>
      <description>&lt;P&gt;The help you need is not how to modify your code. It is your understanding of block concept: You cannot modify entities inside a BlockReference (actually there is no entities inside a BlockReference, except for AtttibuteReference). A block reference is, well, a reference of a block definition (BlockTableRecord) with some geometric transforms, much like a instant image of a block definition placed in different size (scale), location. You can only chane its definition to change the blockreference's look. It is what your code actually does correctly, but not what you want, because if you change a block definition, all its references also change accordingly, as you have found out.&lt;/P&gt;</description>
      <pubDate>Tue, 12 Sep 2017 21:08:31 GMT</pubDate>
      <guid>https://forums.autodesk.com/t5/net-forum/modifying-entities-inside-of-a-cloned-blockreference-also/m-p/7374743#M29651</guid>
      <dc:creator>norman.yuan</dc:creator>
      <dc:date>2017-09-12T21:08:31Z</dc:date>
    </item>
    <item>
      <title>Re: Modifying Entities Inside of a cloned BlockReference also changes the origin</title>
      <link>https://forums.autodesk.com/t5/net-forum/modifying-entities-inside-of-a-cloned-blockreference-also/m-p/7374840#M29652</link>
      <description>&lt;P&gt;Cloning a block reference only creates another reference to the same BlockTableRecord, just as if you had used the COPY command to copy a block reference.&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;You must clone the BlockTableRecord and then modify the entities in the cloned BlockTableRecord.&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;Then you can clone the BlockReference, and set it's BlockTableRecord property to the ObjectId of the clone of the BlockTableRecord.&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;Lastly, you cannot use Clone() to clone most objects. You must use the Database's DeepCloneObjects() method, or for entities (but not BlockTableRecords) you can take a shortcut and invoke the ActiveX Copy() method:&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;PRE&gt;   public static ObjectId Copy(this ObjectId source)
   {
      if(source.IsNull)
         throw new ArgumentException("source");
      dynamic acadObject;
      using(DBObject obj = source.Open(OpenMode.ForRead))
         acadObject = obj.AcadObject;
      return DBObject.FromAcadObject(acadObject.Copy());
   }

&lt;/PRE&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&amp;nbsp;The above method can't be used to clone a BlockTableRecord, only a BlockReference or other Entity-based type.&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;For the BlockTableRecord, you have to use DeepCloneObjects.&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, 12 Sep 2017 21:46:12 GMT</pubDate>
      <guid>https://forums.autodesk.com/t5/net-forum/modifying-entities-inside-of-a-cloned-blockreference-also/m-p/7374840#M29652</guid>
      <dc:creator>ActivistInvestor</dc:creator>
      <dc:date>2017-09-12T21:46:12Z</dc:date>
    </item>
    <item>
      <title>Re: Modifying Entities Inside of a cloned BlockReference also changes the origin</title>
      <link>https://forums.autodesk.com/t5/net-forum/modifying-entities-inside-of-a-cloned-blockreference-also/m-p/7380249#M29653</link>
      <description>&lt;P&gt;Hi, IMO you can&amp;nbsp;explode the blockreference. Then you have all the contents of the blockreference as separate entities.&lt;/P&gt;&lt;P&gt;Then you can do whatever you like with them.&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;From Through-the-interface (&lt;A href="http://through-the-interface.typepad.com/through_the_interface/2011/02/exploding-autocad-objects-using-net.html" target="_blank"&gt;http://through-the-interface.typepad.com/through_the_interface/2011/02/exploding-autocad-objects-using-net.html&lt;/A&gt;&lt;span class="lia-unicode-emoji" title=":disappointed_face:"&gt;😞&lt;/span&gt;&lt;/P&gt;&lt;P&gt;&lt;SPAN&gt;Entity.Explode() is one of those tricky methods: it’s actually a&amp;nbsp;&lt;/SPAN&gt;&lt;A href="http://en.wikipedia.org/wiki/False_friend" target="_blank"&gt;faux-ami&lt;/A&gt;&lt;SPAN&gt;&amp;nbsp;with the AutoCAD command of the same name, in a very similar way to Database.Purge(). The way in which Explode() and Purge() differ from their “equivalent” commands is that they’re non-destructive: they don’t actually result in a change to the AutoCAD drawing database. Explode() populates a DBObjectCollection with the results of the explode operation, and it’s then up to the caller of the function to add them to the appropriate location (typically the current – i.e. model- or paper- – space). Purge() checks a list of objects for ones that can safely be erased, and then it’s up to the caller of the function to do so.&lt;/SPAN&gt;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&lt;SPAN&gt;So using&lt;/SPAN&gt;&lt;/P&gt;&lt;P&gt;&lt;SPAN&gt;DBObjectCollection&amp;nbsp;objs =&amp;nbsp;new&amp;nbsp;DBObjectCollection();&lt;/SPAN&gt;&lt;/P&gt;&lt;P&gt;&lt;SPAN&gt;entity.Explode(objs);&lt;/SPAN&gt;&lt;/P&gt;&lt;P&gt;&lt;SPAN&gt;foreach&lt;/SPAN&gt;&lt;SPAN&gt;&amp;nbsp;(&lt;/SPAN&gt;&lt;SPAN&gt;DBObject&lt;/SPAN&gt;&lt;SPAN&gt;&amp;nbsp;obj&amp;nbsp;&lt;/SPAN&gt;&lt;SPAN&gt;in&lt;/SPAN&gt;&lt;SPAN&gt;&amp;nbsp;objs)&lt;/SPAN&gt;&lt;/P&gt;&lt;P&gt;&lt;SPAN&gt;{&lt;/SPAN&gt;&lt;/P&gt;&lt;P&gt;&lt;SPAN&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&lt;/SPAN&gt;&lt;SPAN&gt;Entity&lt;/SPAN&gt;&lt;SPAN&gt;&amp;nbsp;ent = (&lt;/SPAN&gt;&lt;SPAN&gt;Entity&lt;/SPAN&gt;&lt;SPAN&gt;)obj;&lt;/SPAN&gt;&lt;/P&gt;&lt;P&gt;&lt;SPAN&gt;// Modify to your wishes&lt;/SPAN&gt;&lt;/P&gt;&lt;P&gt;&lt;SPAN&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; btr.AppendEntity(ent);&lt;/SPAN&gt;&lt;/P&gt;&lt;P&gt;&lt;SPAN&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; tr.AddNewlyCreatedDBObject(ent,&amp;nbsp;&lt;/SPAN&gt;&lt;SPAN&gt;true&lt;/SPAN&gt;&lt;SPAN&gt;);&lt;/SPAN&gt;&lt;/P&gt;&lt;P&gt;&lt;SPAN&gt;}&lt;/SPAN&gt;&lt;/P&gt;&lt;P&gt;&lt;SPAN&gt;You'll have the blockreference (ent) still in your drawing, but also have all objects from within the block added to the drawing.&lt;/SPAN&gt;&lt;/P&gt;&lt;P&gt;&lt;SPAN&gt;&amp;nbsp;&lt;/SPAN&gt;&lt;/P&gt;&lt;P&gt;&lt;SPAN&gt;HTH,&lt;/SPAN&gt;&lt;/P&gt;&lt;P&gt;&lt;SPAN&gt;Sietse Wijnker&lt;/SPAN&gt;&lt;/P&gt;</description>
      <pubDate>Thu, 14 Sep 2017 11:55:04 GMT</pubDate>
      <guid>https://forums.autodesk.com/t5/net-forum/modifying-entities-inside-of-a-cloned-blockreference-also/m-p/7380249#M29653</guid>
      <dc:creator>Anonymous</dc:creator>
      <dc:date>2017-09-14T11:55:04Z</dc:date>
    </item>
  </channel>
</rss>

