.NET
cancel
Showing results for 
Show  only  | Search instead for 
Did you mean: 

Unwanted Double Blocks

1 REPLY 1
SOLVED
Reply
Message 1 of 2
drobertsY4GL3
746 Views, 1 Reply

Unwanted Double Blocks

I am handling database.ObjectAppended events to execute some code when a DBObject is added that is a dynamic block of a particular name. This works great if the block is already in model space and is copied. Each copy triggers my event handler and I get one Entity from it.

 

The problem occurs when I drag the same dynamic block off of an insert palette into model space. I get two Entities back, both with different handles, but ultimately only one block is displayed in model space as it should be.

 

Does anyone know why the tool palette is creating an extra block Entity in the database? I should mention I am new to the AutoCAD API.

 

Sudo Code:
// Subscribe to the ObjectAppended database event.
In Event Handler:
// Get the current document and database.
// Cast args to an Entity.
// Check if Entity is a block.
// Check if block is dynamic.
// Cast DynamicBlockTableRecord to BlockTableRecord using Transaction
// Check if BlockTableRecord.Name equals MyBlockName
// Add Entity.Handle to my custom object.

Thank you.

1 REPLY 1
Message 2 of 2

When first creating a dynamic block from the tool palette, two blocks are created. Both have the same BlockTableRecord.Name, but the BlockReference.BlockName differs. One BlockReference.BlockName is a temporary name, while the other block uses a *modelspace(drawingspace, etc.) name. By filtering for both the desired BlockTableRecord.Name and a BlockReference.BlockName containing "*" we get one block returned of the desired name.

 

See sudo code below:

 

Sudo Code:
// Subscribe to the ObjectAppended database event.
In Event Handler:
// Get the current document and database.
// Cast args to an Entity.
// Check if Entity is a block.
// Check if block is dynamic.
// Cast DynamicBlockTableRecord to BlockTableRecord using Transaction
// Check if BlockTableRecord.Name equals MyBlockName
// SOLUTION: 
if (myBlockTableRecord.Name.Equals("MyBlockName") && myBlockRef.BlockName.Contains("*"))
// Add Entity.Handle to my custom object.

 

Can't find what you're looking for? Ask the community or share your knowledge.

Post to forums  

Forma Design Contest


Autodesk Design & Make Report