Insert a block without Duplicate definition of block issue

Insert a block without Duplicate definition of block issue

Anonymous
Not applicable
699 Views
3 Replies
Message 1 of 4

Insert a block without Duplicate definition of block issue

Anonymous
Not applicable
Hi,

We are inserting a layout template using vba as a block. There will be occasional changes to the template. Now the problem is that if the drawing already contains the old block new insertion is ignored by AutoCAD with message Duplicate definition of block 'XXXX' and igbnored. And the changes that contains are not taking effects. How do I can clear the old block definitions and insert the new block. Since there are a number of blocks are there in the template it is difficult to manually delete each block from VBA.

Is there any system variable is out there by setting it up, AutoCAD will replace the block definitions rather than ignoring the new ones. I don't want to just mute the meaage but like to replace the block definitions.

If perge is the only optiion, how i can purge the block definitions in minimum time using VBA.

Thanks in advance
Regards,
Shijith Edited by: spu on Apr 9, 2009 9:35 AM
0 Likes
700 Views
3 Replies
Replies (3)
Message 2 of 4

Anonymous
Not applicable
Try this:



On Error Resume Next
ThisDrawing.Blocks(blockName).Delete
Err.Clear



st0neface
0 Likes
Message 3 of 4

Anonymous
Not applicable
does the block = filename method work for you?

wrote in message news:6159221@discussion.autodesk.com...
Hi, We are inserting a layout template using vba as a block. There will be
occasional changes to the template. Now the problem is that if the drawing
already contains the old block new insertion is ignored by AutoCAD with
message Duplicate definition of block 'XXXX' and igbnored. And the changes
that contains are not taking effects. How do I can clear the old block
definitions and insert the new block. Since there are a number of blocks are
there in the template it is difficult to manually delete each block from
VBA. Is there any system variable is out there by setting it up, AutoCAD
will replace the block definitions rather than ignoring the new ones. I
don't want to just mute the meaage but like to replace the block
definitions. If perge is the only optiion, how i can purge the block
definitions in minimum time using VBA. Thanks in advance Regards, Shijith
Edited by: spu on Apr 9, 2009 9:35 AM
0 Likes
Message 4 of 4

Anonymous
Not applicable
I use the following VBA approach for this condition:

1) Rename the old block definition. So for example if is "MyBlockName", change it to "OldMyBlockName". This is done by simply changing the .Name of the block definition in .Blocks. Keep in mind the distinction between Blocks and BlockRefs.

2) Now insert the new version of "MyBlockName". Since your goal is to replace the original "MyBlockName" instances, you only really need to get the Block definition into the active file. One method in VBA is to insert the block at some odd location and then immediately delete it. At that point you have both the original "MyBlockName" definition and its instances (references) in the active file as an "OldMyBlockName" defintion and "OldMyBlockName" instances plus you also have the new "MyBlockName" definition.

3) Now swap all instances of "OldMyBlockName" with new "MyBlockName" instances. This is simply inserting a "NewBlockName" block at the same location as any instance of "OldMyBlockName", being careful to match layer, rotation, attributes, attribute locations, attribute rotations,, attribute visibility etc. How much stuff you need to match depends on your needs. Then delete the original "OldMyBlockName" instance.

4) There will no longer be any instances of "OldMyBlockName" once you have done step 3 to all instances. Now simply delete the "OldMyBlockName" definition in .Blocks.

All of this sounds like a big task but it actually requires only four functions and it all executes in a fraction of a second. You will find the functions you created for these tasks reusable for many other block related tasks.

aks
0 Likes