<?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: Exploding a block with a nested dynamic block in .NET Forum</title>
    <link>https://forums.autodesk.com/t5/net-forum/exploding-a-block-with-a-nested-dynamic-block/m-p/11425317#M38077</link>
    <description>&lt;P&gt;That seems like a different question to this one so you're probably best posting a new topic for the best chance of getting a reply.&lt;BR /&gt;Not sure if this will help but have a look at this post:&lt;BR /&gt;&lt;A href="https://www.keanw.com/2010/01/creating-an-autocad-block-using-net.html" target="_blank" rel="noopener"&gt;https://www.keanw.com/2010/01/creating-an-autocad-block-using-net.html&lt;/A&gt;&amp;nbsp;&lt;/P&gt;</description>
    <pubDate>Fri, 16 Sep 2022 07:05:14 GMT</pubDate>
    <dc:creator>paul_mace</dc:creator>
    <dc:date>2022-09-16T07:05:14Z</dc:date>
    <item>
      <title>Exploding a block with a nested dynamic block</title>
      <link>https://forums.autodesk.com/t5/net-forum/exploding-a-block-with-a-nested-dynamic-block/m-p/5893800#M38068</link>
      <description>&lt;P&gt;Let's say I have a block called "Car" and a block called "Caravan". The car is a standard block and the caravan is dynamic with options to change the length.&lt;/P&gt;&lt;P&gt;I want my users to be able to insert the car/caravan combination in one go so I combine both blocks into one "Car+Caravan" block but then I explode that block when they insert it. This then means that they have access to the dynamics of the caravan as well as being abe to move the car around independantly of the caravan.&lt;/P&gt;&lt;P&gt;BUT&lt;/P&gt;&lt;P&gt;I want to put the car and caravan in a group so that they will move together if required.&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;So, I've tried the two explode options so far - BlockReference.Explode(idCollection) and BlockReference.ExplodeToOwnerSpace.&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;Method 1: BlockReference.Explode&amp;nbsp;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;PRE&gt;public static ObjectIdCollection ExplodeBlockInsertComponentsAndReturnIdsToGroup(BlockReference blkRef, ref Transaction trans)
{
	Database db = HostApplicationServices.WorkingDatabase;
	BlockTableRecord btr = trans.GetObject(db.CurrentSpaceId, OpenMode.ForRead);
	DBObjectCollection objColl = new DBObjectCollection();
	blkRef.Explode(objColl);
	ObjectIdCollection idsToGroup = new ObjectIdCollection();
	foreach (DBObject obj in objColl) {
		if ((obj) is Entity) {
			ObjectId objId = btr.AppendEntity(obj);
			trans.AddNewlyCreatedDBObject(obj, true);
			idsToGroup.Add(objId);
		}
	}
	return idsToGroup;
}&lt;/PRE&gt;&lt;P&gt;I then&amp;nbsp;create a group using the returned ids.&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;This almost works but the dynaimcs of the Caravan are lost. It doesn't even seem to realise that it's still a block even though all of the entities of the caravan highlight when I select a bit of it.&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;Method 2: Using ExplodeToOwnerSpace with a Database ObjectAppended handler (like in Kean's post here:&lt;A href="http://through-the-interface.typepad.com/through_the_interface/2014/09/exploding-nested-autocad-blocks-using-net.html" target="_blank"&gt;http://through-the-interface.typepad.com/through_the_interface/2014/09/exploding-nested-autocad-blocks-using-net.html&lt;/A&gt;)&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;PRE&gt;        public static ObjectIdCollection idsToGroup;

        public static void ExplodeBlockInsertComponentsAndReturnIdsToGroup(BlockReference blkRef)
        {
            Database db = HostApplicationServices.WorkingDatabase;
            idsToGroup = new ObjectIdCollection();
            db.ObjectAppended += ObjectAppended;
            blkRef.ExplodeToOwnerSpace();
            db.ObjectAppended -= ObjectAppended;
        }

        public static void ObjectAppended(Object sender, ObjectEventArgs e)
        {
            idsToGroup.Add(e.DBObject.ObjectId);
        }&lt;/PRE&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;Again, the returned ids are used to create a group.&lt;/P&gt;&lt;P&gt;I thought I'd cracked it with this as the blocks are grouped and the caravan has the dynamic properties - BUT - as soon as&amp;nbsp;I try to move the group AutoCAD crashes.&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;So, in method 1 I think I'm missing something when I loop through the ObjectIdCollection adding them to the transaction - maybe something to do with the DynamicBlockTableRecord?&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;Method 2 is much closer but the group appears to be corrupt.&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;I'm not doing anything fancy in the grouping code (it works for the ExplodeToOwnerSpace fine) but here's the code for that anyway...&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;PRE&gt;public static bool CreateGroupFromIds(ObjectIdCollection objCol, string blockName, ref Transaction trans)
{
	try {
		Database db = HostApplicationServices.WorkingDatabase;
		string groupName = GroupHelper.GetNextGroupNameForBlock(blockName); // This just gets the next group name for the block 
		Group grp = new Group(groupName, true);
		DBDictionary gd = trans.GetObject(db.GroupDictionaryId, OpenMode.ForWrite);
		gd.SetAt(groupName, grp);
		trans.AddNewlyCreatedDBObject(grp, true);
		grp.InsertAt(0, objCol);
		return true;
	} catch (Exception ex) {
		throw ex;
	}
}&lt;/PRE&gt;&lt;P&gt;I also tried doing the grouping inside a different transaction after the ExplodeToOwnerSpace function, just to make sure that the objects were actually properly in the database but no joy.&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;Thanks in advance for any assistance.&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;P&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Thu, 05 Nov 2015 10:17:59 GMT</pubDate>
      <guid>https://forums.autodesk.com/t5/net-forum/exploding-a-block-with-a-nested-dynamic-block/m-p/5893800#M38068</guid>
      <dc:creator>Paulio</dc:creator>
      <dc:date>2015-11-05T10:17:59Z</dc:date>
    </item>
    <item>
      <title>Re: Exploding a block with a nested dynamic block</title>
      <link>https://forums.autodesk.com/t5/net-forum/exploding-a-block-with-a-nested-dynamic-block/m-p/5900665#M38069</link>
      <description>&lt;P&gt;Attached is a drawing containing a sample block which contains a Car block and a dynamic Caravan block.&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;I don't actually want to insert car and caravan blocks - just using that to illustrate the point.&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;I know it's a bit of a long post but any help would be very gratefully received.&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;P&lt;/P&gt;</description>
      <pubDate>Tue, 10 Nov 2015 09:01:19 GMT</pubDate>
      <guid>https://forums.autodesk.com/t5/net-forum/exploding-a-block-with-a-nested-dynamic-block/m-p/5900665#M38069</guid>
      <dc:creator>Paulio</dc:creator>
      <dc:date>2015-11-10T09:01:19Z</dc:date>
    </item>
    <item>
      <title>Re: Exploding a block with a nested dynamic block</title>
      <link>https://forums.autodesk.com/t5/net-forum/exploding-a-block-with-a-nested-dynamic-block/m-p/5904484#M38070</link>
      <description>&lt;P&gt;Hi Paulio i'm still learning and there's a lot i don't understand, so I cannot tackle your problem head on - but if you hear me out,&amp;nbsp;might I suggest a novel solution:&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;(i) you have the insertion point of the car.&lt;/P&gt;&lt;P&gt;(ii) use the insertioin point of the car to insert the caravan as well in a nearby location. offsert the caravan insertion point by a small amount.&lt;/P&gt;&lt;P&gt;(iii) then group them together.&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&lt;SPAN style="line-height: 15px;"&gt;in other words, use &lt;STRONG&gt;one&lt;/STRONG&gt; insertion point to insert &lt;STRONG&gt;both&lt;/STRONG&gt; the car and caravan - not as one individual block - but as two separate blocks. you can group these blocks together as well.&amp;nbsp;&lt;/SPAN&gt;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;That way you solve your problem of having them inserted together, without the difficulty of exploding them and trying to retain the dynamic block, while also grouping them as well.&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;Hope this helps?&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Thu, 12 Nov 2015 11:02:41 GMT</pubDate>
      <guid>https://forums.autodesk.com/t5/net-forum/exploding-a-block-with-a-nested-dynamic-block/m-p/5904484#M38070</guid>
      <dc:creator>BKSpurgeon</dc:creator>
      <dc:date>2015-11-12T11:02:41Z</dc:date>
    </item>
    <item>
      <title>Re: Exploding a block with a nested dynamic block</title>
      <link>https://forums.autodesk.com/t5/net-forum/exploding-a-block-with-a-nested-dynamic-block/m-p/5904524#M38071</link>
      <description>&lt;P&gt;My problem is that I'm not&amp;nbsp;&lt;EM&gt;actually&lt;/EM&gt; inserting just a car and a caravan block. The real world scenario is a lot more complex where my "combined" block may consist of between 5 and 15 separate blocks that are laid out in a specific configuration at specific spacings etc.&lt;/P&gt;&lt;P&gt;I could try to fully explain the reason I'm trying to do what I'm doing but you'd probably be asleep before I got halfway through!&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;So in short, what you've suggested won't work for me but I appreciate you taking the time to suggest something.&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;P&lt;/P&gt;</description>
      <pubDate>Thu, 12 Nov 2015 11:41:49 GMT</pubDate>
      <guid>https://forums.autodesk.com/t5/net-forum/exploding-a-block-with-a-nested-dynamic-block/m-p/5904524#M38071</guid>
      <dc:creator>Paulio</dc:creator>
      <dc:date>2015-11-12T11:41:49Z</dc:date>
    </item>
    <item>
      <title>Re: Exploding a block with a nested dynamic block</title>
      <link>https://forums.autodesk.com/t5/net-forum/exploding-a-block-with-a-nested-dynamic-block/m-p/5910292#M38072</link>
      <description>At the ObjectAppended, can you check the types and ensure the collection contains only BlockReference?&lt;BR /&gt;&lt;BR /&gt;From your description and by looking at the drawings, it may be missing the fact that DynamicBlocks do create some anonymous blocks (BlockTableRecords) and, maybe, your group is collecting them.&lt;BR /&gt;&lt;BR /&gt;A simple check should work&lt;BR /&gt;&lt;BR /&gt;public static void ObjectAppended(Object sender, ObjectEventArgs e)&lt;BR /&gt;        {&lt;BR /&gt;            if (!(e is BlockReference)) return;&lt;BR /&gt;            idsToGroup.Add(e.DBObject.ObjectId);&lt;BR /&gt;        }</description>
      <pubDate>Mon, 16 Nov 2015 17:47:41 GMT</pubDate>
      <guid>https://forums.autodesk.com/t5/net-forum/exploding-a-block-with-a-nested-dynamic-block/m-p/5910292#M38072</guid>
      <dc:creator>augusto.goncalves</dc:creator>
      <dc:date>2015-11-16T17:47:41Z</dc:date>
    </item>
    <item>
      <title>Re: Exploding a block with a nested dynamic block</title>
      <link>https://forums.autodesk.com/t5/net-forum/exploding-a-block-with-a-nested-dynamic-block/m-p/5911429#M38073</link>
      <description>&lt;P&gt;Hi Augusto,&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;That has indeed solved the problem, thank you.&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;Just for completeness though and for the purposes of future proofing, could you tell me what kinds of objects I should be filtering&amp;nbsp;&lt;EM&gt;out&lt;/EM&gt; rather than specifically allowing through? What I mean is that if I ever have something other than a block reference inside my "blockToExplode"&amp;nbsp;(e.g. linework or text)&amp;nbsp;then those will also get filtered out (and not grouped) using your method.&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;Is it possible to switch your solution around and say something like:&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;if (!(e.dbObject is BlockTableRecord???))&lt;/P&gt;&lt;P&gt;{&lt;/P&gt;&lt;P&gt;&lt;SPAN&gt;&amp;nbsp; idsToGroup.Add(e.DBObject.ObjectId);&lt;/SPAN&gt;&lt;/P&gt;&lt;P&gt;&lt;SPAN&gt;}&lt;/SPAN&gt;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&lt;SPAN&gt;Thanks&amp;nbsp;&lt;/SPAN&gt;&lt;/P&gt;</description>
      <pubDate>Tue, 17 Nov 2015 09:52:36 GMT</pubDate>
      <guid>https://forums.autodesk.com/t5/net-forum/exploding-a-block-with-a-nested-dynamic-block/m-p/5911429#M38073</guid>
      <dc:creator>Paulio</dc:creator>
      <dc:date>2015-11-17T09:52:36Z</dc:date>
    </item>
    <item>
      <title>Re: Exploding a block with a nested dynamic block</title>
      <link>https://forums.autodesk.com/t5/net-forum/exploding-a-block-with-a-nested-dynamic-block/m-p/5911445#M38074</link>
      <description>The Database.ObjectAppended event will trigger for everything on the database, from lines, to block markers (begin/end), linetypes, etc... As in your case you want to create a block, you must filter for entities that fit this condition, in your case, ONLY BlockReference&lt;BR /&gt;&lt;BR /&gt;The BlockTableRecord is actually the block definition and contains the entities. The DynamicBlock will create anonymous blocks (BlockTableRecord), but these are not used on the model space (only the BlockReference is used on model space)&lt;BR /&gt;&lt;BR /&gt;So it's best to filter by what you want (and ignore the rest)</description>
      <pubDate>Tue, 17 Nov 2015 10:05:48 GMT</pubDate>
      <guid>https://forums.autodesk.com/t5/net-forum/exploding-a-block-with-a-nested-dynamic-block/m-p/5911445#M38074</guid>
      <dc:creator>augusto.goncalves</dc:creator>
      <dc:date>2015-11-17T10:05:48Z</dc:date>
    </item>
    <item>
      <title>Re: Exploding a block with a nested dynamic block</title>
      <link>https://forums.autodesk.com/t5/net-forum/exploding-a-block-with-a-nested-dynamic-block/m-p/5911447#M38075</link>
      <description>&lt;P&gt;Ok, that makes sense. I'll just need to add those other object types to my "allowed" list if it becomes necessary then.&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;Thanks for your help.&lt;/P&gt;</description>
      <pubDate>Tue, 17 Nov 2015 10:09:28 GMT</pubDate>
      <guid>https://forums.autodesk.com/t5/net-forum/exploding-a-block-with-a-nested-dynamic-block/m-p/5911447#M38075</guid>
      <dc:creator>Paulio</dc:creator>
      <dc:date>2015-11-17T10:09:28Z</dc:date>
    </item>
    <item>
      <title>Re: Exploding a block with a nested dynamic block</title>
      <link>https://forums.autodesk.com/t5/net-forum/exploding-a-block-with-a-nested-dynamic-block/m-p/11425274#M38076</link>
      <description>&lt;P&gt;Hi Augusto,&lt;/P&gt;&lt;P&gt;I have created template of drawing using line, circle, text etc lot of objects are there now I want all that to in one block so that I can able to scale that block. Please help me in this create any two objects and add them in block by using that object name. I am confused with how to set the block size so that all objects will include in that.&lt;/P&gt;</description>
      <pubDate>Fri, 16 Sep 2022 06:43:16 GMT</pubDate>
      <guid>https://forums.autodesk.com/t5/net-forum/exploding-a-block-with-a-nested-dynamic-block/m-p/11425274#M38076</guid>
      <dc:creator>2020mme013</dc:creator>
      <dc:date>2022-09-16T06:43:16Z</dc:date>
    </item>
    <item>
      <title>Re: Exploding a block with a nested dynamic block</title>
      <link>https://forums.autodesk.com/t5/net-forum/exploding-a-block-with-a-nested-dynamic-block/m-p/11425317#M38077</link>
      <description>&lt;P&gt;That seems like a different question to this one so you're probably best posting a new topic for the best chance of getting a reply.&lt;BR /&gt;Not sure if this will help but have a look at this post:&lt;BR /&gt;&lt;A href="https://www.keanw.com/2010/01/creating-an-autocad-block-using-net.html" target="_blank" rel="noopener"&gt;https://www.keanw.com/2010/01/creating-an-autocad-block-using-net.html&lt;/A&gt;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Fri, 16 Sep 2022 07:05:14 GMT</pubDate>
      <guid>https://forums.autodesk.com/t5/net-forum/exploding-a-block-with-a-nested-dynamic-block/m-p/11425317#M38077</guid>
      <dc:creator>paul_mace</dc:creator>
      <dc:date>2022-09-16T07:05:14Z</dc:date>
    </item>
  </channel>
</rss>

