Generating Dynamic Blocks with parameters

Generating Dynamic Blocks with parameters

kwilcoxS87NH
Explorer Explorer
498 Views
1 Reply
Message 1 of 2

Generating Dynamic Blocks with parameters

kwilcoxS87NH
Explorer
Explorer

Hi, I am working on a system that generates a whole bunch of different dynamic blocks. Every one is basically a very basic block with a couple of basic dynamic parameters, and then a whole bunch of simple entities/static blocks nested in it.

 

I'm trying to automatically generate them because AutoCAD does not support nested dynamic blocks, and it does not support copy/pasting of dynamic block parameters and actions. So the only way for my to conveniently maintain hundreds of blocks is to automate their creation somehow. 

 

My current attempt involves making a template block that contains everything all setup for all of my required blocks, and then my generation code simply makes a renamed duplicate of the template, iterates through its block table record (BTR), and erases specific components.

 

The problem I'm running into is that whenever I modify the BTR for my generated block, it breaks my visibility parameter. Here's what it all looks like:

 

 

Does anyone know why modifying the BTR would break dynamic parameters like this? Does anyone have any ideas how to avoid this? The weird thing is that the blocks are definitely OK after my generation - if I open block editor on any of the "broken" blocks in my DWG, and then just press Test Block, it works fine. If I save it and close it without even making any changes, any block instances in my DWG snap back to life and work fine. But until I do that, they remain broken.

// this is iterating through my generated (duplicated from template) block definition to erase a few nested blocks inside of it
foreach (ObjectId entityId in btr)
{
	BlockReference blockReference = transaction.GetObject(entityId, OpenMode.ForWrite, false, true) as BlockReference;

	if (blockReference == null)
	{
		continue;
	}

	if (!sprinklerDefinition.componentNames.Contains(blockReference.Name))
	{
		DBObject obj = entityId.GetObject(OpenMode.ForWrite);
		
		obj.Erase(); // This is the line that causes my dynamic parameters to "break" on the generated block definition
	}
}

 

0 Likes
Accepted solutions (1)
499 Views
1 Reply
Reply (1)
Message 2 of 2

kwilcoxS87NH
Explorer
Explorer
Accepted solution

Well, that was fun. I discovered that it all works fine if I simply save, close and reopen my DWG file after doing my generation. Some kind of transient data bug. Good old turn it off and back on again. Sorry for needlessly bumping my own post.

0 Likes