Explode a block containing the nested array

Explode a block containing the nested array

fsztuczny
Advocate Advocate
1,016 Views
6 Replies
Message 1 of 7

Explode a block containing the nested array

fsztuczny
Advocate
Advocate

Hello
How to correctly explode a block so that the nested array does not escape from its original place after calling ExplodeToOwnerSpace? My observations show that the array from the exploded block is shifted relative to the original by the double coordinates of the block insertion point (owner).

 

Below is the original block. The colored elements are array:

Przechwytywanie.PNG

 

After ExplodeToOwnerSpace:

Przechwytywanie2.PNG

 

Original drawing is attached.

 

I can make a correction for arrays, but maybe there is another way?

 

My code:

 

		[CommandMethod( "testExplodeToOwnerSpace", CommandFlags.Modal )]
		public void testExplodeToOwnerSpace() // This method can have any name
		{
			// Put your command code here
			try
			{
				Database db = HostApplicationServices.WorkingDatabase;
				Document doc = Autodesk.AutoCAD.ApplicationServices.Application.DocumentManager.MdiActiveDocument;
				Editor ed = doc.Editor;
				PromptEntityOptions peo = new PromptEntityOptions( "\nPick a block: " );
				peo.SetRejectMessage( "\nThis is not a block!" );
				peo.AddAllowedClass( typeof( BlockReference ), true );
				PromptEntityResult per = ed.GetEntity( peo );
				if( per.Status != PromptStatus.OK )
				{
					return;
				}

				using( Transaction tr = doc.TransactionManager.StartTransaction() )
				{
					BlockTableRecord curSpc = tr.GetObject( db.CurrentSpaceId, OpenMode.ForWrite ) as BlockTableRecord;
					BlockReference blRef = tr.GetObject( per.ObjectId, OpenMode.ForWrite ) as BlockReference;
					blRef.ExplodeToOwnerSpace();
					blRef.Erase( true );
					tr.Commit();
				}
			}
			catch( System.Exception ex )
			{
				Autodesk.AutoCAD.ApplicationServices.Application.DocumentManager.MdiActiveDocument.Editor.WriteMessage( ex.ToString() );
			}
		}

 

0 Likes
1,017 Views
6 Replies
Replies (6)
Message 2 of 7

fsztuczny
Advocate
Advocate

Hello

Instead ExplodeToOwnerSpace, another way is:

 

					DBObjectCollection oColl = new DBObjectCollection();
					blRef.Explode( oColl );
					foreach( DBObject obj in oColl )
					{
						Entity ent = obj as Entity;
						curSpc.AppendEntity( ent );
						tr.AddNewlyCreatedDBObject( ent, true );
					}
					oColl.Dispose();

 

 

It works fine.

0 Likes
Message 3 of 7

fsztuczny
Advocate
Advocate

The above solution turns array into a regular block. How to make this block still an array?

0 Likes
Message 4 of 7

norman.yuan
Mentor
Mentor

Array itself is a special BlockReference entity with associatenetwork data applied. While it not only behaves like a dynamic block, its block definition is also an anonymous block definition.

 

However, when array is created from an entity (be it plan single entity, such as circle/line..., or a block reference, as in your case), that single entity would be converted into an block reference of an anonymous block.

 

Then, if you place the array into another block definition, the associatenetwork constraints in the array would be lost, the instance of the array would become only a block reference of an anonymous block definition.

 

When executing command "EXPLODE" at command line against your block with former array block nested (now, just a block reference of an anonymous block, without associated array constraints), the result is the same as calling ExplodeToOwnerSpace() in your code: the "array" (just a regular block reference) would be gone.

 

If you call Explode() and add the exploded DBObejcts into the current space individually, the "array" would remain, as a regular block reference, no array's functionality (because it was lost when your block definition was defined). You could call Explode() recursively to break all block reference, but there would be no array any more. 

 

Norman Yuan

Drive CAD With Code

EESignature

0 Likes
Message 5 of 7

fsztuczny
Advocate
Advocate

Thank you.
I'm aware of what array is and how it works roughly. I asked because the burst built-in command explodes so that the array retains its dynamic characteristics. Similarly, ExplodeToOwnerSpace. That's why I asked because I was looking for an alternative effective way. However, it looks like it will have to stay that way - for now. This is not a drama.
If I understand correctly, ExplodeToOwnerSpace work incorrectly? This is not an intentional feature that must be taken into account for some reason? The graphics are shifted, but the dynamic handles remain in place. I hope Autodesk notices the problem and releases the patch. This problem occurs on AC2012, 2014, 2018 (only these versions I have in the company).

0 Likes
Message 6 of 7

ActivistInvestor
Mentor
Mentor

Have you tried editing the nested associative array in your block definition using the BEDIT command?

0 Likes
Message 7 of 7

fsztuczny
Advocate
Advocate

Yes. Arrays can be edited in the source block. If I burst it with the burst command, the arrays remain editable. If ExplodeToOwnerSpace(), they are also editable but shifted. If Explode() and added to the owner, it remains an anonymous block that contains the copied basic arrays components repeatedly.

 

The dwg drawing is shared a few posts above.

0 Likes